Skip to content

Commit

Permalink
Replace deprecated PythonInterp with Python3 (gazebosim#213) (gazebos…
Browse files Browse the repository at this point in the history
…im#218)

* Replace deprecated PythonInterp with Python3

Signed-off-by: Bi0T1N <[email protected]>
Signed-off-by: Harsh Mahesheka <[email protected]>
  • Loading branch information
j-rivero authored and harshmahesheka committed Apr 5, 2022
1 parent 10df0fd commit c0bfff7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
4 changes: 2 additions & 2 deletions cmake/IgnCodeCheck.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,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)
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 @@ -1713,7 +1713,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 @@ -1736,10 +1735,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

0 comments on commit c0bfff7

Please sign in to comment.