Skip to content

Commit

Permalink
python: bring python 2 support back
Browse files Browse the repository at this point in the history
It was removed in #624, but ROS-CI still needs it.
  • Loading branch information
nim65s committed Oct 30, 2023
1 parent cabe789 commit a897b66
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,16 @@ macro(FINDPYTHON)

# Provide some hints according to the current PYTHON_EXECUTABLE
if(NOT DEFINED PYTHON_INCLUDE_DIR)
if(_PYTHON_VERSION_MAJOR EQUAL "2")
set(PYTHON_INCLUDE_DIR_CMD
"import distutils.sysconfig as sysconfig; print(sysconfig.get_python_inc())"
)
else()
set(PYTHON_INCLUDE_DIR_CMD
"import sysconfig; print(sysconfig.get_path('include'))")
endif()
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" "-c"
"import sysconfig; print(sysconfig.get_path('include'))"
COMMAND "${PYTHON_EXECUTABLE}" "-c" ${PYTHON_INCLUDE_DIR_CMD}
OUTPUT_VARIABLE PYTHON_INCLUDE_DIR
ERROR_QUIET)
string(STRIP "${PYTHON_INCLUDE_DIR}" PYTHON_INCLUDE_DIR)
Expand Down Expand Up @@ -215,9 +222,16 @@ macro(FINDPYTHON)
# Retrieve the corresponding value of PYTHON_INCLUDE_DIR if it is not
# defined
if(NOT DEFINED PYTHON_INCLUDE_DIR)
if(_PYTHON_VERSION_MAJOR EQUAL "2")
set(PYTHON_INCLUDE_DIR_CMD
"import distutils.sysconfig as sysconfig; print(sysconfig.get_python_inc())"
)
else()
set(PYTHON_INCLUDE_DIR_CMD
"import sysconfig; print(sysconfig.get_path('include'))")
endif()
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" "-c"
"import sysconfig; print(sysconfig.get_path('include'))"
COMMAND "${PYTHON_EXECUTABLE}" "-c" ${PYTHON_INCLUDE_DIR_CMD}
OUTPUT_VARIABLE PYTHON_INCLUDE_DIR
ERROR_QUIET)
string(STRIP "${PYTHON_INCLUDE_DIR}" PYTHON_INCLUDE_DIR)
Expand Down Expand Up @@ -269,9 +283,15 @@ macro(FINDPYTHON)
"import sys, os; print(os.sep.join(['lib', 'python' + '.'.join(sys.version.split('.')[:2]), 'site-packages']))"
)
else(PYTHON_STANDARD_LAYOUT)
set(PYTHON_SITELIB_CMD
"import sysconfig; from pathlib import Path; print(Path(sysconfig.get_path('purelib')).relative_to(sysconfig.get_path('data')))"
)
if(_PYTHON_VERSION_MAJOR EQUAL "2")
set(PYTHON_SITELIB_CMD
"from distutils import sysconfig; print(sysconfig.get_python_lib(prefix='', plat_specific=False))"
)
else()
set(PYTHON_SITELIB_CMD
"import sysconfig; from pathlib import Path; print(Path(sysconfig.get_path('purelib')).relative_to(sysconfig.get_path('data')))"
)
endif()
endif(PYTHON_STANDARD_LAYOUT)

execute_process(
Expand Down

0 comments on commit a897b66

Please sign in to comment.