Skip to content

Commit

Permalink
compile installed Python modules and packages by default, add option …
Browse files Browse the repository at this point in the history
…to skip compilation
  • Loading branch information
dirk-thomas committed Aug 7, 2017
1 parent 9810cac commit 372f81e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
15 changes: 13 additions & 2 deletions ament_cmake_python/cmake/ament_python_install_module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
# :param DESTINATION_SUFFIX: the base package to install the module to
# (default: empty, install as a top level module)
# :type DESTINATION_SUFFIX: string
# :param SKIP_COMPILE: if set do not compile the installed module
# :type SKIP_COMPILE: option
#
macro(ament_python_install_module)
_ament_cmake_python_register_environment_hook()
_ament_cmake_python_install_module(${ARGN})
endmacro()

function(_ament_cmake_python_install_module module_file)
cmake_parse_arguments(ARG "" "DESTINATION_SUFFIX" "" ${ARGN})
cmake_parse_arguments(ARG "SKIP_COMPILE" "DESTINATION_SUFFIX" "" ${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "ament_python_install_module() called with unused "
"arguments: ${ARG_UNPARSED_ARGUMENTS}")
Expand Down Expand Up @@ -55,7 +57,16 @@ function(_ament_cmake_python_install_module module_file)
FILES "${module_file}"
DESTINATION "${destination}"
)
# TODO optionally compile Python file
if(NOT ARG_SKIP_COMPILE)
# compile Python files
install(CODE
"execute_process(
COMMAND
\"${PYTHON_EXECUTABLE}\" \"-m\" \"compileall\"
\"${CMAKE_INSTALL_PREFIX}/${destination}/${module_file}\"
)"
)
endif()

if(destination IN_LIST AMENT_CMAKE_PYTHON_INSTALL_INSTALLED_NAMES)
message(FATAL_ERROR "ament_python_install_module() a Python module file "
Expand Down
15 changes: 13 additions & 2 deletions ament_cmake_python/cmake/ament_python_install_package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
# :param PACKAGE_DIR: the path to the Python package directory (default:
# <package_name> folder relative to the CMAKE_CURRENT_LIST_DIR)
# :type PACKAGE_DIR: string
# :param SKIP_COMPILE: if set do not compile the installed package
# :type SKIP_COMPILE: option
#
macro(ament_python_install_package)
_ament_cmake_python_register_environment_hook()
_ament_cmake_python_install_package(${ARGN})
endmacro()

function(_ament_cmake_python_install_package package_name)
cmake_parse_arguments(ARG "" "PACKAGE_DIR" "" ${ARGN})
cmake_parse_arguments(ARG "SKIP_COMPILE" "PACKAGE_DIR" "" ${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "ament_python_install_package() called with unused "
"arguments: ${ARG_UNPARSED_ARGUMENTS}")
Expand Down Expand Up @@ -57,7 +59,16 @@ function(_ament_cmake_python_install_package package_name)
PATTERN "*.pyc" EXCLUDE
PATTERN "__pycache__" EXCLUDE
)
# TODO(dirk-thomas): optionally compile Python files
if(NOT ARG_SKIP_COMPILE)
# compile Python files
install(CODE
"execute_process(
COMMAND
\"${PYTHON_EXECUTABLE}\" \"-m\" \"compileall\"
\"${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTALL_DIR}/${package_name}\"
)"
)
endif()

if(package_name IN_LIST AMENT_CMAKE_PYTHON_INSTALL_INSTALLED_NAMES)
message(FATAL_ERROR
Expand Down

0 comments on commit 372f81e

Please sign in to comment.