Skip to content

Make ament_python_install_package() install console_scripts #328

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

Merged
merged 3 commits into from
May 10, 2021
Merged
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
46 changes: 39 additions & 7 deletions ament_cmake_python/cmake/ament_python_install_package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
# :param SETUP_CFG: the path to a setup.cfg file (default:
# setup.cfg file at CMAKE_CURRENT_LIST_DIR root, if any)
# :param SETUP_CFG: string
# :param DESTINATION: the path to the Python package installation
# directory (default: PYTHON_INSTALL_DIR)
# :type DESTINATION: string
# :param SCRIPTS_DESTINATION: the path to the Python package scripts'
# installation directory, scripts (if any) will be ignored if not set
# :type SCRIPTS_DESTINATION: string
# :param SKIP_COMPILE: if set do not byte-compile the installed package
# :type SKIP_COMPILE: option
#
Expand All @@ -34,7 +40,8 @@ macro(ament_python_install_package)
endmacro()

function(_ament_cmake_python_install_package package_name)
cmake_parse_arguments(ARG "SKIP_COMPILE" "PACKAGE_DIR;VERSION;SETUP_CFG" "" ${ARGN})
cmake_parse_arguments(
ARG "SKIP_COMPILE" "PACKAGE_DIR;VERSION;SETUP_CFG;DESTINATION;SCRIPTS_DESTINATION" "" ${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "ament_python_install_package() called with unused "
"arguments: ${ARG_UNPARSED_ARGUMENTS}")
Expand Down Expand Up @@ -68,9 +75,12 @@ function(_ament_cmake_python_install_package package_name)
set(ARG_SETUP_CFG "${CMAKE_CURRENT_LIST_DIR}/${ARG_SETUP_CFG}")
endif()

if(NOT PYTHON_INSTALL_DIR)
message(FATAL_ERROR "ament_python_install_package() variable "
"'PYTHON_INSTALL_DIR' must not be empty")
if(NOT ARG_DESTINATION)
if(NOT PYTHON_INSTALL_DIR)
message(FATAL_ERROR "ament_python_install_package() variable "
"'PYTHON_INSTALL_DIR' must not be empty")
endif()
set(ARG_DESTINATION ${PYTHON_INSTALL_DIR})
endif()

set(build_dir "${CMAKE_CURRENT_BINARY_DIR}/ament_cmake_python/${package_name}")
Expand Down Expand Up @@ -119,12 +129,34 @@ setup(

install(
DIRECTORY "${build_dir}/${package_name}.egg-info"
DESTINATION "${PYTHON_INSTALL_DIR}/"
DESTINATION "${ARG_DESTINATION}/"
)

if(ARG_SCRIPTS_DESTINATION)
file(MAKE_DIRECTORY "${build_dir}/scripts") # setup.py may or may not create it

add_custom_target(
ament_cmake_python_build_${package_name}_scripts ALL
COMMAND ${PYTHON_EXECUTABLE} setup.py install_scripts -d scripts
WORKING_DIRECTORY "${build_dir}"
DEPENDS ${egg_dependencies}
)

if(NOT AMENT_CMAKE_SYMLINK_INSTALL)
# Not needed for nor supported by symlink installs
set(_extra_install_args USE_SOURCE_PERMISSIONS)
endif()

install(
DIRECTORY "${build_dir}/scripts/"
DESTINATION "${ARG_SCRIPTS_DESTINATION}/"
${_extra_install_args}
)
endif()

install(
DIRECTORY "${ARG_PACKAGE_DIR}/"
DESTINATION "${PYTHON_INSTALL_DIR}/${package_name}"
DESTINATION "${ARG_DESTINATION}/${package_name}"
PATTERN "*.pyc" EXCLUDE
PATTERN "__pycache__" EXCLUDE
)
Expand All @@ -135,7 +167,7 @@ setup(
"execute_process(
COMMAND
\"${PYTHON_EXECUTABLE}\" \"-m\" \"compileall\"
\"${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_DIR}/${package_name}\"
\"${CMAKE_INSTALL_PREFIX}/${ARG_DESTINATION}/${package_name}\"
)"
)
endif()
Expand Down