Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated PythonInterp with Python3 #213

Merged
merged 2 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmake/IgnCodeCheck.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ function(ign_setup_target_for_codecheck)
DEPENDS cppcheck
)

if(PYTHONINTERP_FOUND)
if(Python3_Interpreter_FOUND)
add_custom_target(cpplint
COMMAND ${PYTHON_EXECUTABLE} ${IGNITION_CMAKE_CODECHECK_DIR}/cpplint.py --extensions=cc,hh --quiet `${CPPCHECK_FIND}`
COMMAND ${Python3_EXECUTABLE} ${IGNITION_CMAKE_CODECHECK_DIR}/cpplint.py --extensions=cc,hh --quiet `${CPPCHECK_FIND}`
)

add_dependencies(codecheck cpplint)
Expand Down
30 changes: 22 additions & 8 deletions cmake/IgnPython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,28 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Copied from ament/ament_cmake: ament_cmake/ament_cmake_core/cmake/core/python.cmake
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.19")
set(IGN_PYTHON_VERSION "" CACHE STRING
"Specify specific Python3 version to use ('major.minor' or 'versionMin...[<]versionMax')")

set(PYTHON_VERSION "" CACHE STRING
"Specify specific Python version to use ('major.minor' or 'major')")
find_package(Python3 ${IGN_PYTHON_VERSION} QUIET)
elseif(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12")
# no support for finding specific versions
find_package(Python3 QUIET)
Bi0T1N marked this conversation as resolved.
Show resolved Hide resolved
else()
# TODO: remove this block as soon as the CMake version can safely be bumped to => 3.12
set(IGN_PYTHON_VERSION "" CACHE STRING
"Specify specific Python version to use ('major.minor' or 'major')")

# if not specified otherwise use Python 3
if(NOT PYTHON_VERSION)
set(PYTHON_VERSION "3")
endif()
# if not specified otherwise use Python 3
if(NOT IGN_PYTHON_VERSION)
set(IGN_PYTHON_VERSION "3")
endif()

find_package(PythonInterp ${PYTHON_VERSION} QUIET)
find_package(PythonInterp ${IGN_PYTHON_VERSION} QUIET)

if(PYTHONINTERP_FOUND)
set(Python3_Interpreter_FOUND ${PYTHONINTERP_FOUND})
set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE})
endif()
endif()
5 changes: 2 additions & 3 deletions cmake/IgnUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1695,7 +1695,6 @@ macro(ign_build_tests)

# Find the Python interpreter for running the
# check_test_ran.py script

include(IgnPython)

# Build all the tests
Expand All @@ -1715,10 +1714,10 @@ macro(ign_build_tests)

set_tests_properties(${target_name} PROPERTIES TIMEOUT 240)

if(PYTHONINTERP_FOUND)
if(Python3_Interpreter_FOUND)
# Check that the test produced a result and create a failure if it didn't.
# Guards against crashed and timed out tests.
add_test(check_${target_name} ${PYTHON_EXECUTABLE} ${IGNITION_CMAKE_TOOLS_DIR}/check_test_ran.py
add_test(check_${target_name} ${Python3_EXECUTABLE} ${IGNITION_CMAKE_TOOLS_DIR}/check_test_ran.py
${CMAKE_BINARY_DIR}/test_results/${target_name}.xml)
endif()
endforeach()
Expand Down