From 69178c98c72e103e7811cd1683bc60d0cbe0fdf7 Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Fri, 10 Oct 2025 11:19:59 -0500 Subject: [PATCH 1/2] Improve byte-compile in ament_cmake_python - Align CMake documentation - Suppress verbose output from compileall - Add a CMake-like installation message - Fix support for DESTDIR-based installations Signed-off-by: Scott K Logan --- .../cmake/ament_python_install_module.cmake | 10 ++++++---- .../cmake/ament_python_install_package.cmake | 8 +++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ament_cmake_python/cmake/ament_python_install_module.cmake b/ament_cmake_python/cmake/ament_python_install_module.cmake index 6d61edcc..c4f576b4 100644 --- a/ament_cmake_python/cmake/ament_python_install_module.cmake +++ b/ament_cmake_python/cmake/ament_python_install_module.cmake @@ -20,7 +20,7 @@ # :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 +# :param SKIP_COMPILE: if set do not byte-compile the installed module # :type SKIP_COMPILE: option # macro(ament_python_install_module) @@ -60,12 +60,14 @@ function(_ament_cmake_python_install_module module_file) get_filename_component(module_file "${module_file}" NAME) if(NOT ARG_SKIP_COMPILE) get_executable_path(python_interpreter Python3::Interpreter CONFIGURE) + set(_bytecompile_target "\$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${ARG_DESTINATION}/${module_file}") # compile Python files install(CODE - "execute_process( + "message(STATUS \"Byte-compiling: ${_bytecompile_target}\") + execute_process( COMMAND - \"${python_interpreter}\" \"-m\" \"compileall\" - \"${CMAKE_INSTALL_PREFIX}/${destination}/${module_file}\" + \"${python_interpreter}\" \"-m\" \"compileall\" \"-q\" + \"${_bytecompile_target}\" )" ) endif() diff --git a/ament_cmake_python/cmake/ament_python_install_package.cmake b/ament_cmake_python/cmake/ament_python_install_package.cmake index 25a08092..0ea40b98 100644 --- a/ament_cmake_python/cmake/ament_python_install_package.cmake +++ b/ament_cmake_python/cmake/ament_python_install_package.cmake @@ -190,12 +190,14 @@ setup( if(NOT ARG_SKIP_COMPILE) get_executable_path(python_interpreter_config Python3::Interpreter CONFIGURE) + set(_bytecompile_target "\$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${ARG_DESTINATION}/${package_name}") # compile Python files install(CODE - "execute_process( + "message(STATUS \"Byte-compiling: ${_bytecompile_target}\") + execute_process( COMMAND - \"${python_interpreter_config}\" \"-m\" \"compileall\" - \"${CMAKE_INSTALL_PREFIX}/${ARG_DESTINATION}/${package_name}\" + \"${python_interpreter_config}\" \"-m\" \"compileall\" \"-q\" + \"${_bytecompile_target}\" )" ) endif() From 7dd0c5fd00c6970daa1ea0a344ea31022358f521 Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Fri, 14 Nov 2025 14:36:34 -0600 Subject: [PATCH 2/2] Drop unused ARG_DESTINATION Co-authored-by: Shane Loretz Signed-off-by: Scott K Logan --- ament_cmake_python/cmake/ament_python_install_module.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ament_cmake_python/cmake/ament_python_install_module.cmake b/ament_cmake_python/cmake/ament_python_install_module.cmake index c4f576b4..e2413d52 100644 --- a/ament_cmake_python/cmake/ament_python_install_module.cmake +++ b/ament_cmake_python/cmake/ament_python_install_module.cmake @@ -60,7 +60,7 @@ function(_ament_cmake_python_install_module module_file) get_filename_component(module_file "${module_file}" NAME) if(NOT ARG_SKIP_COMPILE) get_executable_path(python_interpreter Python3::Interpreter CONFIGURE) - set(_bytecompile_target "\$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${ARG_DESTINATION}/${module_file}") + set(_bytecompile_target "\$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${destination}/${module_file}") # compile Python files install(CODE "message(STATUS \"Byte-compiling: ${_bytecompile_target}\")