Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install pip dependencies using local virtualenv, also support install target #184

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ catkin_package(
catkin-pip.cmake
catkin-pip-runcmd.cmake
catkin-pip-package.cmake
catkin-pip-package-virtualenv.cmake
catkin-pip-prefix.cmake
catkin-pip-requirements.cmake
pytest.cmake
Expand Down
46 changes: 46 additions & 0 deletions cmake/catkin-pip-package-virtualenv.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
if ( CMAKE_BACKWARDS_COMPATIBILITY LESS 2.8 )
message ( FATAL_ERROR " CMAKE MINIMUM BACKWARD COMPATIBILITY REQUIRED : 2.8 !" )
endif( CMAKE_BACKWARDS_COMPATIBILITY LESS 2.8 )

# Enforcing one time include https://cmake.org/Wiki/CMake_Performance_Tips#Use_an_include_guard
if(catkin_pip_target_virtualenv_included)
return()
endif(catkin_pip_target_virtualenv_included)
set(catkin_pip_target_virtualenv_included true)

message(STATUS "Loading catkin-pip-package-virtualenv.cmake from ${CMAKE_CURRENT_LIST_DIR}... ")


# catkin_pip_package override catkin_pip_package, otherwise CATKIN_PIP_ENV directory
## ned to call `catkin_pip_requirements` after `catkin_pip_package_virtualenv`
macro(catkin_pip_package_virtualenv package_name)
if (NOT ${package_name} STREQUAL ${PROJECT_NAME})
message(FATAL_ERROR "We assume package_name(${package_name}) is equal to PROJECT_NAME(${PROJECT_NAME})")
endif()

unset(CATKIN_VIRTUALENV CACHE)
find_program(CATKIN_VIRTUALENV NAMES virtualenv)
# call catkin_package() to set CATKIN_PACKAGE_SHARE_DESTINATION

set(CATKIN_VIRTUALENV_PATH_${PROJECT_NAME} ${CATKIN_DEVEL_PREFIX}/share/${PROJECT_NAME}/catkin_pip_env CACHE PATH "The virtual eivironment for each package")
message("-- Set local virtual env path to CATKIN_VIRTUALENV_PATH_${PROJECT_NAME} : ${CATKIN_VIRTUALENV_PATH_${PROJECT_NAME}}")
message("-- Install local virutalenv to ${CATKIN_VIRTUALENV_PATH_${PROJECT_NAME}}")
catkin_pip_runcmd(python ${CATKIN_VIRTUALENV} -q --system-site-packages ${CATKIN_VIRTUALENV_PATH_${PROJECT_NAME}})
### HACK somehow virtualenv create local dir, which shows two python.exe when we run `rosrun <pkg> python`
catkin_pip_runcmd(cmake -E remove_directory ${CATKIN_VIRTUALENV_PATH_${PROJECT_NAME}}/local)

## OVERRIDE catkin_pip_env
unset(CATKIN_PIP_ENV CACHE)
set(CATKIN_PIP_ENV ${CATKIN_VIRTUALENV_PATH_${PROJECT_NAME}})

## copy virtualenv path to install directory
install(DIRECTORY ${CATKIN_DEVEL_PREFIX}/share/${PROJECT_NAME}/catkin_pip_env/
DESTINATION share/${PROJECT_NAME}/catkin_pip_env
USE_SOURCE_PERMISSIONS
PATTERN "${PROJECT_NAME}.egg-link" EXCLUDE
)

## RUN catkin_pip_package
catkin_pip_package(${package_name})
endmacro()

8 changes: 8 additions & 0 deletions cmake/catkin-pip-package.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ function(catkin_pip_python_setup)
assert(CATKIN_PIP_PYTHON_INSTALL_DIR)
set(INSTALL_CMD_WORKING_DIRECTORY ${package_path})

set(__CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
# tmp override CMAKE_INSTLAL_PREIFX for virutalenv setup
if (CATKIN_VIRTUALENV_PATH_${PROJECT_NAME})
set(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/catkin_pip_env)
endif()
if(NOT WIN32)
set(INSTALL_SCRIPT
${CMAKE_CURRENT_BINARY_DIR}/catkin_generated/python_setuptools_install.sh)
Expand All @@ -64,10 +69,12 @@ function(catkin_pip_python_setup)
${INSTALL_SCRIPT}
@ONLY)
endif()
set(CMAKE_INSTALL_PREFIX ${__CMAKE_INSTALL_PREFIX})

# generate python script which gets executed at install time
configure_file(${catkin_EXTRAS_DIR}/templates/safe_execute_install.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/catkin_generated/safe_execute_install.cmake)

install(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/catkin_generated/safe_execute_install.cmake)

# END : This is the end of catkin_python_setup copy
Expand All @@ -92,6 +99,7 @@ function(catkin_pip_target package_name)

set(${PROJECT_NAME}_PIP_TARGET ${package_name} CACHE STRING "Make target generated to install this pip package as --editable for development")

catkin_pip_setup_prefix(${CATKIN_VIRTUALENV_PATH_${PROJECT_NAME}})
# Note : environment should already be setup at configure time for devel

# Then we can run the pip command
Expand Down
9 changes: 8 additions & 1 deletion cmake/catkin-pip-requirements.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ function(catkin_pip_requirements requirements_txt)
# Needed in case user call this directly (configure time)
catkin_pip_setup_prefix(${CATKIN_PIP_ENV})

# If catkin_pip_use_viertualenv is set, install within package path, other wise install devel prefix
if(CATKIN_VIRTUALENV_PATH_${PROJECT_NAME})
set(_pip_install_prefix ${CATKIN_VIRTUALENV_PATH_${PROJECT_NAME}})
else()
set(_pip_install_prefix ${CATKIN_DEVEL_PREFIX})
endif()

# runnig the pip command (configure time)
catkin_pip_runcmd(${CATKIN_PIP} install ${ARGN} -r ${requirements_txt} --ignore-installed --src ${CMAKE_SOURCE_DIR} --exists-action b --prefix "${CATKIN_DEVEL_PREFIX}")
catkin_pip_runcmd(${CATKIN_PIP} install ${ARGN} -r ${requirements_txt} --ignore-installed --src ${CMAKE_SOURCE_DIR} --exists-action b --prefix "${_pip_install_prefix}")

endfunction()
12 changes: 11 additions & 1 deletion cmake/catkin-pip-runcmd.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,21 @@ endfunction()


function(catkin_pip_install_devel_target package_name package_path)

# If catkin_pip_use_viertualenv is set, install within package path, other wise install devel prefix
if (CATKIN_VIRTUALENV_PATH_${PROJECT_NAME})
set(_pip_install_prefix ${CATKIN_VIRTUALENV_PATH_${PROJECT_NAME}})
set(CATKIN_PIP_INSTALL_DEVEL_OUTPUTS
${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_SHARE_DESTINATION}/${CATKIN_PIP_PYTHON_INSTALL_DIR}/${package_name}.egg-link
)
else()
set(_pip_install_prefix ${CATKIN_DEVEL_PREFIX})
set(CATKIN_PIP_INSTALL_DEVEL_OUTPUTS
# ${CATKIN_DEVEL_PREFIX}/${CATKIN_PIP_PYTHON_INSTALL_DIR}/easy-install.pth
# CAREFUL with multiple outputs : https://cmake.org/Bug/view.php?id=15116
${CATKIN_DEVEL_PREFIX}/${CATKIN_PIP_PYTHON_INSTALL_DIR}/${package_name}.egg-link
)
endif()

string(REPLACE ";" " " ARGN_STR "${ARGN}")

Expand All @@ -56,7 +66,7 @@ function(catkin_pip_install_devel_target package_name package_path)


set(CATKIN_PIP_CMD ${CATKIN_ENV})
set(CATKIN_PIP_CMD_ARGS_STR "flock ${CATKIN_PIP_ENV}/catkin_pip.lock ${CATKIN_PIP} install -e ${package_path} --prefix ${CATKIN_DEVEL_PREFIX} ${ARGN_STR}")
set(CATKIN_PIP_CMD_ARGS_STR "flock ${CATKIN_PIP_ENV}/catkin_pip.lock ${CATKIN_PIP} install -e ${package_path} --prefix ${_pip_install_prefix} ${ARGN_STR}")
# IF WE ARE PASSING EDITABLE PKG PATHS INTO PYTHONPATH we need to work around bug :
# PYTHONPATH breaks pip install --editable Ref : https://github.com/pypa/pip/issues/4261
# set(CATKIN_PIP_CMD_ARGS_STR "-c 'export PYTHONPATH=${CATKIN_DEVEL_PREFIX}/${CATKIN_PIP_PYTHON_INSTALL_DIR}:${CATKIN_PIP_ENV}/${CATKIN_PIP_PYTHON_INSTALL_DIR}\; ${CATKIN_PIP_CMD_ARGS_STR}'")
Expand Down
6 changes: 6 additions & 0 deletions cmake/catkin-pip.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ IF ( NOT CATKIN_PIP_PACKAGE_FOUND )
message ( FATAL_ERROR "${CMAKE_CURRENT_LIST_DIR}/catkin-pip-package.cmake Not Found !!!" )
ENDIF ( NOT CATKIN_PIP_PACKAGE_FOUND )

# protecting against missing cmake file dependency
include ( "${CMAKE_CURRENT_LIST_DIR}/catkin-pip-package-virtualenv.cmake" RESULT_VARIABLE CATKIN_PIP_PACKAGE_VIRTUALENV_FOUND )
IF ( NOT CATKIN_PIP_PACKAGE_VIRTUALENV_FOUND )
message ( FATAL_ERROR "${CMAKE_CURRENT_LIST_DIR}/catkin-pip-package-virtualenv.cmake Not Found !!!" )
ENDIF ( NOT CATKIN_PIP_PACKAGE_VIRTUALENV_FOUND )

# Setting our paths to package env-hooks provided by catkin-pip
if ( NOT CATKIN_PIP_ENV_HOOKS_PATH )
# templates should be found relative to our current path
Expand Down