From 9b5935c61603cd8b296b3f9eccbefe99647466ff Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Sat, 16 Oct 2021 20:47:03 +0200 Subject: [PATCH 1/2] Fix handling of multiple namespaced python packages in devel space If there are multiple packages to be installed below a common namespace, only the last one installed is found in devel space, because the path extension is always overwritten. This PR augments the existing __extended_path. --- cmake/catkin_python_setup.cmake | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cmake/catkin_python_setup.cmake b/cmake/catkin_python_setup.cmake index e360706f3..d0f6ca163 100644 --- a/cmake/catkin_python_setup.cmake +++ b/cmake/catkin_python_setup.cmake @@ -80,11 +80,17 @@ function(catkin_python_setup) if(NOT ("${pkg}" STREQUAL "${name}")) message(FATAL_ERROR "The package name '${pkg}' differs from the basename of the path '${pkg_dir}' in project '${PROJECT_NAME}'") endif() + # Retrieve PACKAGE_PYTHONPATH from existing __init__.py + set(target_init_file ${CATKIN_DEVEL_PREFIX}/${PYTHON_INSTALL_DIR}/${pkg}/__init__.py) + if(EXISTS ${target_init_file}) + file(READ ${target_init_file} file_content) + string(REGEX MATCH "__extended_path *= *'(.*)'\\.split" _ "${file_content}") + set(PACKAGE_PYTHONPATH ${CMAKE_MATCH_1}) + endif() + # Extend PACKAGE_PYTHONPATH with current pkg's path get_filename_component(path ${pkg_dir} PATH) - set(PACKAGE_PYTHONPATH ${CMAKE_CURRENT_SOURCE_DIR}/${path}) - configure_file(${catkin_EXTRAS_DIR}/templates/__init__.py.in - ${CATKIN_DEVEL_PREFIX}/${PYTHON_INSTALL_DIR}/${pkg}/__init__.py - @ONLY) + list(APPEND PACKAGE_PYTHONPATH ${CMAKE_CURRENT_SOURCE_DIR}/${path}) + configure_file(${catkin_EXTRAS_DIR}/templates/__init__.py.in ${target_init_file} @ONLY) endforeach() endif() From 9b2c06f10595b2f5ff0eda201e9c3fe6705c42d8 Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Thu, 21 Oct 2021 17:00:29 +0200 Subject: [PATCH 2/2] Avoid adding duplicates --- cmake/catkin_python_setup.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/catkin_python_setup.cmake b/cmake/catkin_python_setup.cmake index d0f6ca163..2880d752f 100644 --- a/cmake/catkin_python_setup.cmake +++ b/cmake/catkin_python_setup.cmake @@ -89,7 +89,7 @@ function(catkin_python_setup) endif() # Extend PACKAGE_PYTHONPATH with current pkg's path get_filename_component(path ${pkg_dir} PATH) - list(APPEND PACKAGE_PYTHONPATH ${CMAKE_CURRENT_SOURCE_DIR}/${path}) + list_append_deduplicate(PACKAGE_PYTHONPATH ${CMAKE_CURRENT_SOURCE_DIR}/${path}) configure_file(${catkin_EXTRAS_DIR}/templates/__init__.py.in ${target_init_file} @ONLY) endforeach() endif()