Skip to content

Commit

Permalink
fixed python cmake integration
Browse files Browse the repository at this point in the history
  • Loading branch information
john-chrosniak committed Oct 30, 2024
1 parent cdf0758 commit b376ba9
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# if it is a local installation.
find_package( PythonInterp )
if( PYTHONINTERP_FOUND )
get_filename_component( _python_path ${PYTHON_EXECUTABLE} PATH )
get_filename_component( _python_path ${Python3_EXECUTABLE} PATH )
find_program( CYTHON_EXECUTABLE
NAMES cython cython.bat cython3
HINTS ${_python_path}
Expand Down
2 changes: 1 addition & 1 deletion mrt_cmake_modules/cmake/Modules/CatkinMockForConan.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ conan_define_targets()
target_link_libraries(${PROJECT_NAME}::auto_deps_export INTERFACE ${CONAN_TARGETS})
if(CONAN_USER_PYTHON_DEV_CONFIG_python_exec)
set(PYTHON_VERSION ${CONAN_USER_PYTHON_DEV_CONFIG_python_version})
set(PYTHON_EXECUTABLE ${CONAN_USER_PYTHON_DEV_CONFIG_python_exec})
set(Python3_EXECUTABLE ${CONAN_USER_PYTHON_DEV_CONFIG_python_exec})
endif()

set(CATKIN_DEVEL_PREFIX ${CMAKE_CURRENT_BINARY_DIR})
Expand Down
4 changes: 2 additions & 2 deletions mrt_cmake_modules/cmake/Modules/FindBoostPython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# BoostPython_INCLUDE_DIRS - the include directory for boost+python
# BoostPython_LIBRARIES - the needed libs for boost+python

if(PYTHON_VERSION)
set(_python_version ${PYTHON_VERSION})
if(Python3_VERSION)
set(_python_version ${Python3_VERSION})
else()
set(_python_version 2.7)
endif()
Expand Down
8 changes: 4 additions & 4 deletions mrt_cmake_modules/cmake/Modules/MrtTesting.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function(mrt_init_testing)
endif()
if(NOT TARGET init_tests)
set(pre_test_cmd
${PYTHON_EXECUTABLE}
${Python3_EXECUTABLE}
${MRT_CMAKE_MODULES_ROOT_PATH}/scripts/init_coverage.py
${PROJECT_NAME}
${CMAKE_BINARY_DIR}
Expand All @@ -61,7 +61,7 @@ function(mrt_init_testing)
set(show_result "--show")
endif()
set(post_test_cmd
${PYTHON_EXECUTABLE}
${Python3_EXECUTABLE}
${MRT_CMAKE_MODULES_ROOT_PATH}/scripts/eval_coverage.py
${CMAKE_SOURCE_DIR}
${CMAKE_BINARY_DIR}
Expand Down Expand Up @@ -115,7 +115,7 @@ function(_mrt_run_test target_name working_dir result_xml_path)

set(run_test_cmd
${CATKIN_ENV}
${PYTHON_EXECUTABLE}
${Python3_EXECUTABLE}
${MRT_CMAKE_MODULES_ROOT_PATH}/scripts/run_test.py
${result_xml_path}
${working_dir_arg}
Expand Down Expand Up @@ -205,7 +205,7 @@ function(mrt_add_rostest target launch_file)
message(FATAL_ERROR "rostest not found! Aborting...")
endif()
set(cmd
"${PYTHON_EXECUTABLE} ${ROSTEST_EXE} --pkgdir=${PROJECT_SOURCE_DIR} --package=${PROJECT_NAME} --results-filename ${test_name}.xml --results-base-dir \"${MRT_TEST_RESULTS_DIR}\" ${CMAKE_CURRENT_LIST_DIR}/${launch_file}"
"${Python3_EXECUTABLE} ${ROSTEST_EXE} --pkgdir=${PROJECT_SOURCE_DIR} --package=${PROJECT_NAME} --results-filename ${test_name}.xml --results-base-dir \"${MRT_TEST_RESULTS_DIR}\" ${CMAKE_CURRENT_LIST_DIR}/${launch_file}"
)
if(MRT_ENABLE_COVERAGE)
set(coverage_arg COVERAGE_DIR ${MRT_COVERAGE_DIR}/${target})
Expand Down
2 changes: 1 addition & 1 deletion mrt_cmake_modules/cmake/Templates/python_api_install.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import os
import sys
import subprocess

python_interpreter = "@PYTHON_EXECUTABLE@"
python_interpreter = "@Python3_EXECUTABLE@"
if not python_interpreter:
python_interpreter = "python"

Expand Down
10 changes: 5 additions & 5 deletions mrt_cmake_modules/cmake/mrt_cmake_modules-macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ if(DEFINED ENV{ROS_VERSION})
set(ROS_VERSION $ENV{ROS_VERSION})
endif()

# make sure catkin/ament are found so that PYTHON_EXECUTABLE (and CATKIN_ENV) is set.
# make sure catkin/ament are found so that Python3_EXECUTABLE (and CATKIN_ENV) is set.
if(NOT PYTHON_VERSION AND DEFINED $ENV{ROS_PYTHON_VERSION})
set(PYTHON_VERSION
$ENV{ROS_PYTHON_VERSION}
Expand Down Expand Up @@ -394,7 +394,7 @@ function(_mrt_get_python_destination output_var)
"print(os.path.relpath(get_python_lib(prefix='${CMAKE_INSTALL_PREFIX}'), start='${CMAKE_INSTALL_PREFIX}').replace(os.sep, '/'))"
)
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" "-c" "${_python_code}"
COMMAND "${Python3_EXECUTABLE}" "-c" "${_python_code}"
OUTPUT_VARIABLE _output
RESULT_VARIABLE _result
OUTPUT_STRIP_TRAILING_WHITESPACE)
Expand Down Expand Up @@ -604,7 +604,7 @@ function(mrt_python_module_setup)
install(
CODE "execute_process(
COMMAND
\"${PYTHON_EXECUTABLE}\" \"-m\" \"compileall\"
\"${Python3_EXECUTABLE}\" \"-m\" \"compileall\"
\"${CMAKE_INSTALL_PREFIX}/${python_destination}/${PROJECT_NAME}\"
)")
if(ROS_VERSION EQUAL 2)
Expand Down Expand Up @@ -727,7 +727,7 @@ function(mrt_add_python_api modulename)
configure_file(${MCM_TEMPLATE_DIR}/setup.py.in "${CMAKE_CURRENT_BINARY_DIR}/setup.py" @ONLY)
configure_file(${MCM_TEMPLATE_DIR}/python_api_install.py.in "${CMAKE_CURRENT_BINARY_DIR}/python_api_install.py"
@ONLY)
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/python_api_install.py)")
install(CODE "execute_process(COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/python_api_install.py)")
else()
if(ROS_VERSION EQUAL 2)
_mrt_register_ament_python_hook()
Expand Down Expand Up @@ -1353,7 +1353,7 @@ function(_mrt_install_python source_file destination)
string(SUBSTRING "${data}" 0 ${length} prefix)
if("${shebang_line}" STREQUAL "${prefix}")
# write modified file with modified shebang line
get_filename_component(python_name ${PYTHON_EXECUTABLE} NAME)
get_filename_component(python_name ${Python3_EXECUTABLE} NAME)
string(REGEX REPLACE "${regex}" "#!/\\1/env ${python_name}\\2" data "${data}")
get_filename_component(filename ${source_file} NAME)
set(rewritten_file "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/python_files")
Expand Down

0 comments on commit b376ba9

Please sign in to comment.