Skip to content

Commit

Permalink
Merge pull request #28 from asmodehn/separate_catkin_pip_env
Browse files Browse the repository at this point in the history
separating catkin_pip environment with workspace environment.
  • Loading branch information
asmodehn authored Aug 9, 2016
2 parents c171038 + 29b1e3d commit 286d0f0
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 40 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ catkin_package(
configure_file(cmake/catkin-pip-base.req ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_SHARE_DESTINATION}/cmake/catkin-pip-base.req COPYONLY)
configure_file(cmake/catkin-pip-fixups.req ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_SHARE_DESTINATION}/cmake/catkin-pip-fixups.req COPYONLY)
configure_file(cmake/env-hooks/42.site_packages.bash.develspace.in ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_SHARE_DESTINATION}/cmake/env-hooks/42.site_packages.bash.develspace.in COPYONLY)
configure_file(cmake/templates/python_setuptools_install.bat.in ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_SHARE_DESTINATION}/cmake/templates/python_setuptools_install.bat.in COPYONLY)
configure_file(cmake/env-hooks/42.site_packages.bash.installspace.in ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_SHARE_DESTINATION}/cmake/env-hooks/42.site_packages.bash.installspace.in COPYONLY)
#configure_file(cmake/templates/python_setuptools_install.bat.in ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_SHARE_DESTINATION}/cmake/templates/python_setuptools_install.bat.in COPYONLY)
configure_file(cmake/templates/python_setuptools_install.sh.in ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_SHARE_DESTINATION}/cmake/templates/python_setuptools_install.sh.in COPYONLY)

# to be found in install space and from package
Expand All @@ -52,12 +53,13 @@ install(PROGRAMS
# We install in cmake folder the files that are needed by cmake code
install(FILES
cmake/env-hooks/42.site_packages.bash.develspace.in
cmake/env-hooks/42.site_packages.bash.installspace.in
DESTINATION
${CATKIN_PACKAGE_SHARE_DESTINATION}/cmake/env-hooks
)

install(PROGRAMS
cmake/templates/python_setuptools_install.bat.in
# cmake/templates/python_setuptools_install.bat.in
cmake/templates/python_setuptools_install.sh.in
DESTINATION
${CATKIN_PACKAGE_SHARE_DESTINATION}/cmake/templates
Expand Down
5 changes: 0 additions & 5 deletions cmake/catkin-pip-env.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ macro(catkin_pip_check_env config_prefix)
"Quick patch will be applied to the current cmake process environment."
)

if ( FOUND_PPATH LESS 0 )
message(STATUS "Adding ${config_prefix}/@CATKIN_GLOBAL_PYTHON_DESTINATION@ to PYTHONPATH")
set(ENV{PYTHONPATH} "${config_prefix}/@CATKIN_GLOBAL_PYTHON_DESTINATION@:$ENV{PYTHONPATH}")
endif()

if ( FOUND_PPPATH LESS 0 )
message(STATUS "Adding ${config_prefix}/@CATKIN_PIP_GLOBAL_PYTHON_DESTINATION@ to PYTHONPATH")
set(ENV{PYTHONPATH} "${config_prefix}/@CATKIN_PIP_GLOBAL_PYTHON_DESTINATION@:$ENV{PYTHONPATH}")
Expand Down
4 changes: 0 additions & 4 deletions cmake/catkin-pip-prefix.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ macro(catkin_pip_setup_prefix ws_prefix)
message( FATAL_ERROR "pip system command not found. Make sure you have installed the python-pip package on your system.")
endif()

# message(STATUS " ... Creating pip packages prefix ...")
# If needed we create the directory (to avoid later errors)
# file(MAKE_DIRECTORY ${ws_prefix}/@CATKIN_PIP_GLOBAL_PYTHON_DESTINATION@)

message(STATUS " ... Retrieving catkin_pip requirements using system pip ...")

# We need to find a pip command that works for old pip versions (indigo supports trusty which is pip v1.5.4)
Expand Down
1 change: 1 addition & 0 deletions cmake/catkin-pip-setup.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function(catkin_pip_python_setup)
#

assert(PYTHON_INSTALL_DIR)
assert(CATKIN_PIP_PYTHON_INSTALL_DIR)
set(INSTALL_CMD_WORKING_DIRECTORY ${package_path})

if(NOT WIN32)
Expand Down
10 changes: 8 additions & 2 deletions cmake/catkin-pip.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@ if ( NOT CATKIN_PIP_ENV_HOOKS_PATH )
set (CATKIN_PIP_ENV_HOOKS_PATH ${CMAKE_CURRENT_LIST_DIR}/env-hooks)
endif()

# We want the catkin environment to be used for both devel and install workspace
# to use latest versions python tools in both.
set(CATKIN_PIP_ENV ${CMAKE_BINARY_DIR}/catkin_pip_env CACHE PATH "The path containing the python environment for catkin_pip dependencies" )
set(CATKIN_PIP_PYTHON_INSTALL_DIR @CATKIN_PIP_GLOBAL_PYTHON_DESTINATION@)

# Since we need the envhook as soon as a package is using catkin-pip from source, but only in devel space
catkin_add_env_hooks(42.site_packages SHELLS bash DIRECTORY ${CATKIN_PIP_ENV_HOOKS_PATH} SKIP_INSTALL)
catkin_add_env_hooks(42.site_packages SHELLS bash DIRECTORY ${CATKIN_PIP_ENV_HOOKS_PATH})
# TODO : cmake should include this file only once, so the env hook is not recreated for every package that includes it...

catkin_pip_setup_prefix(${CATKIN_DEVEL_PREFIX})
catkin_pip_setup_prefix(${CATKIN_PIP_ENV})

#
# Install Space should have same behavior as package build
# We want to check dependencies are all satisfied, without relying on pip requirements.
# But we want to use latest version python libraries (especially setuptools)
#
10 changes: 8 additions & 2 deletions cmake/env-hooks/42.site_packages.bash.develspace.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@
CATKIN_PIP_SCRIPTS="$(rospack find catkin_pip)/scripts"
echo "Catkin-pip scripts found in $CATKIN_PIP_SCRIPTS"

#We need first the catkin_pip_env
# Careful : echo is only possible if we are a bash script (not used by env.sh)
echo "Prepending @CATKIN_PIP_ENV@/@CATKIN_PIP_PYTHON_INSTALL_DIR@ to PYTHONPATH"
PYTHONPATH=$("${CATKIN_PIP_SCRIPTS}"/pythonpath_prepend.bash "@CATKIN_PIP_ENV@/@CATKIN_PIP_PYTHON_INSTALL_DIR@")
# TODO : maybe we should to that in .sh envhook, so that env.sh would set it up before any command we want to run (Check CATKIN_ENV doc)...

# We combine it with site-packages (pip default) location, before attempting to prepend to the python path
# Careful : echo is only possible if we are a bash script (not used by env.sh)
echo "Prepending @CATKIN_DEVEL_PREFIX@/lib/python2.7/site-packages to PYTHONPATH"
PYTHONPATH=$("${CATKIN_PIP_SCRIPTS}"/pythonpath_prepend.bash "@CATKIN_DEVEL_PREFIX@/lib/python2.7/site-packages")
echo "Prepending @CATKIN_DEVEL_PREFIX@/@CATKIN_PIP_PYTHON_INSTALL_DIR@ to PYTHONPATH"
PYTHONPATH=$("${CATKIN_PIP_SCRIPTS}"/pythonpath_prepend.bash "@CATKIN_DEVEL_PREFIX@/@CATKIN_PIP_PYTHON_INSTALL_DIR@")

# to avoid side effect with multiple workspace having different version of catkin_pip
unset CATKIN_PIP_SCRIPTS
29 changes: 29 additions & 0 deletions cmake/env-hooks/42.site_packages.bash.installspace.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
# Careful : env.sh *executes* it during cmake configure, but setup.sh source it !
# If using a sh script, this can make a lot of issues...
# Reference to address these from a Bourne shell http://stackoverflow.com/a/29835459

# For catkin it is simpler to do add site-packages to PYTHONPATH in _setup_util.py.in than us doing it from here...
# but until catkin does this by default, the proper way from outside catkin is probably a env-hook

##Documentation:
# The colon command simply has its arguments evaluated and then succeeds.
# It is the original shell comment notation (before '#' to end of line). For a long time, Bourne shell scripts had a colon as the first character.
# The C Shell would read a script and use the first character to determine whether it was for the C Shell (a '#' hash) or the Bourne shell (a ':' colon).
# Then the kernel got in on the act and added support for '#!/path/to/program' and the Bourne shell got '#' comments, and the colon convention went by the wayside.
# But if you come across a script that starts with a colon (Like this one), now you will know why. ~ Jonathan Leffler

# We should enable site-package only on devel space.
# Install space should behave like packages, everything in debian layout.

# finding our useful script from catkin_pip using rospack (work from source or bin package)
CATKIN_PIP_SCRIPTS="$(rospack find catkin_pip)/scripts"
echo "Catkin-pip scripts found in $CATKIN_PIP_SCRIPTS"

# We need ONLY the catkin_pip_env
# Careful : echo is only possible if we are a bash script (not used by env.sh)
echo "Prepending @CATKIN_PIP_ENV@/@CATKIN_PIP_PYTHON_INSTALL_DIR@ to PYTHONPATH"
PYTHONPATH=$("${CATKIN_PIP_SCRIPTS}"/pythonpath_prepend.bash "@CATKIN_PIP_ENV@/@CATKIN_PIP_PYTHON_INSTALL_DIR@")

# to avoid side effect with multiple workspace having different version of catkin_pip
unset CATKIN_PIP_SCRIPTS
2 changes: 1 addition & 1 deletion cmake/nosetests.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ find_program(PIP_NOSETESTS NAMES
"nosetests-${PYTHON_VERSION_MAJOR}"
"nosetests"
PATHS
${CATKIN_DEVEL_PREFIX}/@CATKIN_GLOBAL_BIN_DESTINATION@
${CATKIN_PIP_ENV}/@CATKIN_GLOBAL_BIN_DESTINATION@
NO_DEFAULT_PATH
)
if(PIP_NOSETESTS)
Expand Down
2 changes: 1 addition & 1 deletion cmake/pytest.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ find_program(PIP_PYTEST NAMES
"py.test-${PYTHON_VERSION_MAJOR}"
"py.test"
PATHS
${CATKIN_DEVEL_PREFIX}/@CATKIN_GLOBAL_BIN_DESTINATION@
${CATKIN_PIP_ENV}/@CATKIN_GLOBAL_BIN_DESTINATION@
NO_DEFAULT_PATH
)
if(PIP_PYTEST)
Expand Down
17 changes: 0 additions & 17 deletions cmake/templates/python_setuptools_install.bat.in

This file was deleted.

20 changes: 14 additions & 6 deletions cmake/templates/python_setuptools_install.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,33 @@ if [ -n "$DESTDIR" ] ; then
/bin/echo "otherwise python's distutils will bork things."
exit 1
esac
DESTDIR_ARG="--single-version-externally-managed --root=$DESTDIR"
DESTDIR_ARG="--root=$DESTDIR"
else
DESTDIR_ARG="--record=@CMAKE_INSTALL_PREFIX@/@[email protected]"
fi

echo_and_run() { echo "+ $@" ; "$@" ; }

echo_and_run cd "@INSTALL_CMD_WORKING_DIRECTORY@"

# snsure that Python install destination exists
echo_and_run mkdir -p "$DESTDIR@CMAKE_INSTALL_PREFIX@/@PYTHON_INSTALL_DIR@"
# Ensure that Python install destination exists
# Not needed with latest setuptools ?
#echo_and_run mkdir -p "$DESTDIR@CMAKE_INSTALL_PREFIX@/@PYTHON_INSTALL_DIR@"

# Verifying setuptools version
echo_and_run /usr/bin/env \
PYTHONPATH="@CATKIN_PIP_ENV@/@CATKIN_PIP_PYTHON_INSTALL_DIR@:@CMAKE_INSTALL_PREFIX@/@PYTHON_INSTALL_DIR@:@CMAKE_BINARY_DIR@/@PYTHON_INSTALL_DIR@:$PYTHONPATH" \
python -c "import setuptools; print 'setuptools from {0} version {1}'.format(setuptools.__file__, setuptools.__version__)"

# Note that PYTHONPATH is pulled from the environment to support installing
# into one location when some dependencies were installed in another
# location, #123.
# One of these locations must be the catkin_pip_env with the latest setuptools version to install packages with recent setuptools.
echo_and_run /usr/bin/env \
PYTHONPATH="@CMAKE_INSTALL_PREFIX@/@PYTHON_INSTALL_DIR@:@CMAKE_BINARY_DIR@/@PYTHON_INSTALL_DIR@:$PYTHONPATH" \
CATKIN_BINARY_DIR="@CMAKE_BINARY_DIR@" \
PYTHONPATH="@CATKIN_PIP_ENV@/@CATKIN_PIP_PYTHON_INSTALL_DIR@:@CMAKE_INSTALL_PREFIX@/@PYTHON_INSTALL_DIR@:@CMAKE_BINARY_DIR@/@PYTHON_INSTALL_DIR@:$PYTHONPATH" \
"@PYTHON_EXECUTABLE@" \
"@CATKIN_PIP_PACKAGE_PATH@/setup.py" \
build --build-base "@CMAKE_CURRENT_BINARY_DIR@" \
install \
install --single-version-externally-managed \
$DESTDIR_ARG \
@SETUPTOOLS_ARG_EXTRA@ --prefix="@CMAKE_INSTALL_PREFIX@" --install-scripts="@CMAKE_INSTALL_PREFIX@/@CATKIN_GLOBAL_BIN_DESTINATION@"

0 comments on commit 286d0f0

Please sign in to comment.