diff --git a/tools/cmake/CheckPythonPackage.cmake b/tools/cmake/CheckPythonPackage.cmake index 7e86172f53..47a4341562 100644 --- a/tools/cmake/CheckPythonPackage.cmake +++ b/tools/cmake/CheckPythonPackage.cmake @@ -2,12 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 # CMake functions for checking for Python packages -# Requires PYTHON_EXECUTABLE to be defined. Call FindPythonInterp first! - -# NOTE: if moving this file, be sure to also move python_packagecheck.py - -# must evaluate this now since CMAKE_CURRENT_LIST_DIR doesn't work in function scope -set(PYTHON_PACKAGECHECK_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/python_packagecheck.py) +# Requires PYTHON_EXECUTABLE to be defined. Call FindPython first! # set OUTPUT_VAR to whether PACKAGENAME was found function(check_python_package PACKAGENAME OUTPUT_VAR) @@ -35,7 +30,7 @@ function(check_python_package PACKAGENAME OUTPUT_VAR) set(PY_INTERP_FOR_${OUTPUT_VAR} ${Python3_EXECUTABLE} CACHE INTERNAL "The python interpreter used to run the ${OUTPUT_VAR} check" FORCE) execute_process( - COMMAND ${Python3_EXECUTABLE} ${PYTHON_PACKAGECHECK_SCRIPT} ${PACKAGENAME} RESULT_VARIABLE PACKAGECHECK_RESULT + COMMAND ${Python3_EXECUTABLE} -c "import ${PACKAGENAME}" RESULT_VARIABLE PACKAGECHECK_RESULT ) if(${PACKAGECHECK_RESULT} EQUAL 0) @@ -67,5 +62,5 @@ function(verify_python_package PACKAGENAME) if(NOT ${HAVE_VAR_NAME}) message(FATAL_ERROR "The required Python package ${PACKAGENAME} was not found in ${Python3_EXECUTABLE}. Please install it.") endif() - + endfunction(verify_python_package) diff --git a/tools/cmake/python_packagecheck.py b/tools/cmake/python_packagecheck.py deleted file mode 100644 index 3cd75abd3f..0000000000 --- a/tools/cmake/python_packagecheck.py +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (c) 2020 ARM Limited. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 - -"""Script to check if a Python module/package is installed.""" - -import sys - -try: - __import__(sys.argv[1]) -except ImportError: - exit(1) - -exit(0)