Skip to content

Commit

Permalink
[feature] Improve Python bindings packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-bremond committed Jan 9, 2019
1 parent 3c1eae7 commit 74a3fc2
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 32 deletions.
1 change: 0 additions & 1 deletion bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ ADD_CUSTOM_COMMAND (OUTPUT ${OUTPUT}
COMMAND mkdir -p "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_PATH}"
COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/tools/python/Library/__init__.py" "${CMAKE_CURRENT_BINARY_DIR}/Library/__init__.py"
COMMAND cp "${CMAKE_CURRENT_SOURCE_DIR}/tools/python/${PROJECT_PATH}/__init__.py" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_PATH}/__init__.py"
COMMAND cp "/usr/local/lib/libboost_python36.so.1.68.0" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_PATH}/libboost_python36.so.1.68.0"
COMMAND cp "/usr/local/lib/libboost_numpy36.so.1.68.0" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_PATH}/libboost_numpy36.so.1.68.0"
COMMAND cp "${CMAKE_SOURCE_DIR}/lib/${SHARED_LIBRARY_TARGET}" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_PATH}/liblibrary-mathematics.so.0"
COMMAND cp "${CMAKE_SOURCE_DIR}/lib/${LIBRARY_TARGET}" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_PATH}/LibraryMathematicsPy.so"
Expand Down
13 changes: 13 additions & 0 deletions bindings/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
################################################################################################################################################################

# @project Library/Mathematics
# @file requirements.txt
# @author Lucas Brémond <[email protected]>
# @license Apache License 2.0

################################################################################################################################################################

numpy
LibraryCorePy>=0.2.0

################################################################################################################################################################
15 changes: 14 additions & 1 deletion bindings/python/tools/python/Library/Mathematics/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
from .LibraryMathematicsPy import *
################################################################################################################################################################

# @project Library/Mathematics
# @file Library/Mathematics/__init__.py
# @author Lucas Brémond <[email protected]>
# @license Apache License 2.0

################################################################################################################################################################

from Library.Core import *

from .LibraryMathematicsPy import *

################################################################################################################################################################
8 changes: 8 additions & 0 deletions bindings/python/tools/python/Library/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
################################################################################################################################################################

# @project Library
# @file Library/__init__.py
# @author Lucas Brémond <[email protected]>
# @license Apache License 2.0

################################################################################################################################################################
57 changes: 39 additions & 18 deletions bindings/python/tools/python/setup.py.in
Original file line number Diff line number Diff line change
@@ -1,24 +1,45 @@
################################################################################################################################################################

# @project Library/Mathematics
# @file tools/python/setup.py.in
# @author Lucas Brémond <[email protected]>
# @license Apache License 2.0

################################################################################################################################################################

import setuptools

with open("${CMAKE_CURRENT_SOURCE_DIR}/README.md", "r") as fh:
with open('${CMAKE_CURRENT_SOURCE_DIR}/README.md', 'r') as fh:
long_description = fh.read()

with open('${CMAKE_CURRENT_SOURCE_DIR}/requirements.txt', 'r') as f:
requirements = f.read().splitlines()

setuptools.setup(
name="LibraryMathematicsPy",
version="${PROJECT_VERSION_STRING}",
author="Open Space Collective",
author_email="[email protected]",
description="Fundamental types, containers and utilities.",
long_description=long_description,
long_description_content_type="text/markdown",
url = "https://github.com/open-space-collective/library-mathematics",
classifiers=(
"Development Status :: 3 - Alpha",
"Programming Language :: Python :: 3",
"License :: OSI Approved :: Apache Software License",
"Operating System :: POSIX :: Linux"
name = 'LibraryMathematicsPy',
version = '${PROJECT_VERSION_STRING}',
author = 'Open Space Collective',
author_email = '[email protected]',
description = 'Geometry, curve fitting, optimization.',
long_description = long_description,
long_description_content_type = 'text/markdown',
url = 'https://github.com/open-space-collective/library-mathematics',
classifiers = (
'Development Status :: 3 - Alpha',
'Programming Language :: Python :: 3',
'License :: OSI Approved :: Apache Software License',
'Operating System :: POSIX :: Linux'
),
keywords="open-space-collective mathematics",
packages=setuptools.find_packages(),
package_data={"": ["${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_PATH}/LibraryMathematicsPy.so", "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_PATH}/liblibrary-mathematics.so.0", "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_PATH}/libboost_python36.so.1.68.0", "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_PATH}/libboost_numpy36.so.1.68.0"]}
)
keywords = 'open-space-collective library mathematics',
packages = setuptools.find_packages(),
package_data = {
'': [
'${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_PATH}/LibraryMathematicsPy.so',
'${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_PATH}/liblibrary-mathematics.so.0',
'${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_PATH}/libboost_numpy36.so.1.68.0'
]
},
install_requires = requirements
)

################################################################################################################################################################
36 changes: 24 additions & 12 deletions tools/python/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,41 @@ if [[ ! -z $1 ]] && [[ $1 == "--link" ]]; then
&& echo 'from .LibraryMathematicsPy import *' > /opt/conda/lib/python3.6/site-packages/Library/Mathematics/__init__.py \
&& start-notebook.sh --NotebookApp.token=''"

# docker run \
# --name="${container_name}-notebook" \
# -it \
# --rm \
# --publish="${python_port}:8888" \
# --user="" \
# --env="JUPYTER_ENABLE_LAB=yes" \
# --env="LD_LIBRARY_PATH=/usr/local/lib:/opt/conda/lib/python3.6/site-packages:/home/jovyan/lib" \
# --env="PYTHONPATH=/opt/conda/lib/python3.6/site-packages:/home/jovyan/lib" \
# --volume="${library_core_directory}/lib:/opt/library-core:ro" \
# --volume="${project_directory}/lib:/opt/lib:ro" \
# --volume="${project_directory}/bindings/python/docs:/home/jovyan/docs" \
# --volume="${project_directory}/tutorials/python/notebooks:/home/jovyan/tutorials" \
# --volume="${project_directory}/share/data:/app/share/data" \
# --workdir="/home/jovyan" \
# "${image_name}-python:${image_version}" \
# bash -c "mkdir -p /opt/conda/lib/python3.6/site-packages/Library/Mathematics \
# && ln -s /opt/lib/liblibrary-mathematics.so.0 /opt/conda/lib/python3.6/site-packages/Library/Mathematics/liblibrary-mathematics.so.0 \
# && ln -s /opt/lib/LibraryMathematicsPy.so /opt/conda/lib/python3.6/site-packages/Library/Mathematics/LibraryMathematicsPy.so \
# && echo 'from .LibraryMathematicsPy import *' > /opt/conda/lib/python3.6/site-packages/Library/Mathematics/__init__.py \
# && start-notebook.sh --NotebookApp.token=''"

else

docker run \
--name="${container_name}-notebook" \
-it \
--rm \
--publish="${python_port}:8888" \
--user="" \
--env="JUPYTER_ENABLE_LAB=yes" \
--env="LD_LIBRARY_PATH=/usr/local/lib:/opt/conda/lib/python3.6/site-packages:/home/jovyan/lib" \
--env="PYTHONPATH=/opt/conda/lib/python3.6/site-packages:/home/jovyan/lib" \
--volume="${library_core_directory}/lib:/opt/library-core:ro" \
--volume="${project_directory}/lib:/opt/lib:ro" \
--volume="${project_directory}/bindings/python/docs:/home/jovyan/docs" \
--volume="${project_directory}/tutorials/python/notebooks:/home/jovyan/tutorials" \
--volume="${project_directory}/share/data:/app/share/data" \
--workdir="/home/jovyan" \
"${image_name}-python:${image_version}" \
bash -c "mkdir -p /opt/conda/lib/python3.6/site-packages/Library/Mathematics \
&& ln -s /opt/lib/liblibrary-mathematics.so.0 /opt/conda/lib/python3.6/site-packages/Library/Mathematics/liblibrary-mathematics.so.0 \
&& ln -s /opt/lib/LibraryMathematicsPy.so /opt/conda/lib/python3.6/site-packages/Library/Mathematics/LibraryMathematicsPy.so \
&& echo 'from .LibraryMathematicsPy import *' > /opt/conda/lib/python3.6/site-packages/Library/Mathematics/__init__.py \
&& start-notebook.sh --NotebookApp.token=''"
"jupyter/scipy-notebook:latest" \
start-notebook.sh --NotebookApp.token=''

fi

Expand Down

0 comments on commit 74a3fc2

Please sign in to comment.