Skip to content

Commit

Permalink
First skeleton of hbp-spatial-backend
Browse files Browse the repository at this point in the history
  • Loading branch information
ylep committed Feb 13, 2019
0 parents commit 98b7f06
Show file tree
Hide file tree
Showing 17 changed files with 1,244 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# http://editorconfig.org

root = true

# Defaults for every file
[*]
charset = utf-8
end_of_line = lf
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.py]
indent_style = space
indent_size = 4

[*.json]
indent_size = 2

# Makefiles must use tabs for indentation
[Makefile]
indent_style = tab
55 changes: 55 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
.pytest_cache/
htmlcov/
.tox/
.coverage
.coverage.*
.cache
coverage.xml
*.cover

# Flask stuff:
instance/
.webassets-cache

# Sphinx documentation
docs/_build/

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: python
# The next two lines are here to fix build with Pyton 3.7, see
# https://github.com/travis-ci/travis-ci/issues/9069#issuecomment-425720905
sudo: required
dist: xenial
python:
- "3.5"
- "3.6"
- "3.7"
install: pip install tox-travis
script: tox
661 changes: 661 additions & 0 deletions LICENCE.txt

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
include LICENCE.txt
include .coveragerc
include .editorconfig
include *.ini
include *.sh

prune docker-aims
prune docker-backend

recursive-include tests *.py
28 changes: 28 additions & 0 deletions docker-aims/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM ubuntu:16.04

RUN apt-get update \
&& apt-get install -y --no-install-recommends --no-install-suggests \
libblitz0v5 \
libsigc++-2.0-0v5 \
libxml2 \
libqtcore4 \
zlib1g \
python2.7 \
python-sip \
libpython2.7 \
python-pip \
python-six \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# We need to use the same version of numpy as casa-dev:ubuntu-16.04
# RUN pip install --disable-pip-version-check --no-cache-dir \
# numpy==1.13.1

COPY install /usr/local
RUN ldconfig

# Make the BrainVISA Python packages visible to the system
RUN mkdir -p /usr/local/lib/python2.7/dist-packages \
&& cd /usr/local/lib/python2.7/dist-packages \
&& ln -s ../../../python/* .
55 changes: 55 additions & 0 deletions docker-aims/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Run from the directory that contains this script (docker-aims)

CASA_DISTRO_DIR=/volatile/bv/casa_distro_repo

casa_distro \
-r "$CASA_DISTRO_DIR" \
create \
distro_name=aims \
distro_source=opensource \
branch=bug_fix \
system=ubuntu-16.04

cat <<'EOF' > "$CASA_DISTRO_DIR"/aims/bug_fix_ubuntu-16.04/conf/bv_maker.cfg
[ source $CASA_SRC ]
brainvisa brainvisa-cmake $CASA_BRANCH
brainvisa soma-base $CASA_BRANCH
brainvisa soma-io $CASA_BRANCH
brainvisa aims-free $CASA_BRANCH
[ build $CASA_BUILD ]
default_steps = configure build
make_options = -j16
build_type = Release
packaging_thirdparty = OFF
clean_config = ON
clean_build = ON
test_ref_data_dir = $CASA_TESTS/ref
test_run_data_dir = $CASA_TESTS/test
brainvisa brainvisa-cmake $CASA_BRANCH $CASA_SRC
brainvisa soma-base $CASA_BRANCH $CASA_SRC
brainvisa soma-io $CASA_BRANCH $CASA_SRC
brainvisa aims-free $CASA_BRANCH $CASA_SRC
EOF

casa_distro \
-r "$CASA_DISTRO_DIR" \
bv_maker \
distro=aims \
branch=bug_fix \
system=ubuntu-16.04

casa_distro \
-r "$CASA_DISTRO_DIR" \
run \
distro=aims \
branch=bug_fix \
system=ubuntu-16.04 \
/bin/sh -c 'cd /casa/build && make install-runtime BRAINVISA_INSTALL_PREFIX=/casa/install'

cp -a "$CASA_DISTRO_DIR"/aims/bug_fix_ubuntu-16.04/install .

DOCKER_IMAGE=brainvisa-aims:bug_fix_$(date -Id)
docker build -t $DOCKER_IMAGE .

docker save -o $DOCKER_IMAGE.tar $DOCKER_IMAGE
10 changes: 10 additions & 0 deletions docker-backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM brainvisa-aims:latest

RUN apt-get update \
&& apt-get install -y --no-install-recommends --no-install-suggests \
python3 \
python3-pip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN pip3 install --no-cache-dir -r requirements.txt
71 changes: 71 additions & 0 deletions hbp_spatial_backend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright 2019 CEA
# Author: Yann Leprince <[email protected]>
#
# This file is part of hbp-spatial-backend.
#
# hbp-spatial-backend is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# hbp-spatial-backend is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
# for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with hbp-spatial-backend. If not, see <https://www.gnu.org/licenses/>.

import os

import flask


# __version__ and SOURCE_URL are used by setup.py and docs/conf.py (they are
# parsed with a regular expression, so keep the syntax simple).
__version__ = '0.1.0.dev0'

# URL that holds the source code of the backend. This must be changed to
# point to the exact code of any modified version, in order to comply with
# the AGPL licence.
SOURCE_URL = 'https://github.com/HumanBrainProject/hbp-spatial-backend'


class DefaultConfig:
CORS_ALLOW_ALL = True


# This function has a magic name which is recognized by flask as a factory for
# the main app.
def create_app(test_config=None):
app = flask.Flask(__name__,
instance_path=os.environ.get("INSTANCE_PATH"),
instance_relative_config=True)

app.config.from_object(DefaultConfig)
if test_config is None:
# load the instance config, if it exists, when not testing
app.config.from_pyfile("config.py", silent=True)
app.config.from_envvar("HBP_SPATIAL_BACKEND_SETTINGS", silent=True)
else:
# load the test config if passed in
app.config.from_mapping(test_config)

# ensure the instance folder exists
try:
os.makedirs(app.instance_path)
except OSError:
pass

if app.config["CORS_ALLOW_ALL"]:
import flask_cors
flask_cors.CORS(app)

@app.route("/source")
def root():
return flask.redirect(SOURCE_URL)

import hbp_spatial_backend.api_v1
hbp_spatial_backend.api_v1.register_api(app, prefix='/v1')

return app
52 changes: 52 additions & 0 deletions hbp_spatial_backend/api_v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2019 CEA
# Author: Yann Leprince <[email protected]>
#
# This file is part of hbp-spatial-backend.
#
# hbp-spatial-backend is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# hbp-spatial-backend is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
# for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with hbp-spatial-backend. If not, see <https://www.gnu.org/licenses/>.

import flask_restful
import flask_restful.reqparse


def tuple_3floats(input_sequence):
'''Convert a variable to a tuple of 3 floats
TypeError is raised if the conversion is not possible.
'''
input_tuple = tuple(input_sequence)
if len(input_tuple) != 3:
raise TypeError('the input sequence is not of length 3')
return tuple(float(x) for x in input_tuple)


class TransformPointApi(flask_restful.Resource):
def get(self):
parser = flask_restful.reqparse.RequestParser()
parser.add_argument('source_space', required=True, location='json')
parser.add_argument('target_space', required=True, location='json')
parser.add_argument('source_point', required=True,
type=tuple_3floats, location='json')
args = parser.parse_args(strict=True)
# transform_chain = transform_graph.get_chain(source_space,
# target_space)
# target_point = apply_transform.transform_point(source_point,
# transform_chain)
target_point = args.source_point
return {'target_point': target_point}


def register_api(app, *args, **kwargs):
api = flask_restful.Api(app, *args, **kwargs)
api.add_resource(TransformPointApi, '/transform-point')
8 changes: 8 additions & 0 deletions run-flask-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/sh -e

PYTHONPATH=$(dirname -- "$0")${PYTHONPATH+:}$PYTHONPATH
FLASK_APP=hbp_spatial_backend
FLASK_ENV=development
export PYTHONPATH FLASK_APP FLASK_ENV

flask run "$@"
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[aliases]
test = pytest
Loading

0 comments on commit 98b7f06

Please sign in to comment.