From e2ecc410e9d15a85fdb8b6dcdea154616d24d71c Mon Sep 17 00:00:00 2001 From: Kyle Knoepfel Date: Tue, 23 Dec 2025 11:18:15 -0600 Subject: [PATCH 1/2] Use find_package arguments to mandate NumPy This change allows a CMake-only replacement to introducing numpy build dependencies. Also included is the replacement of one find_package(Python3 ...) command with find_package(Python ...) as Python2 is not supported. --- Modules/private/CreateCoverageTargets.cmake | 4 +- plugins/python/CMakeLists.txt | 108 ++++---------------- 2 files changed, 22 insertions(+), 90 deletions(-) diff --git a/Modules/private/CreateCoverageTargets.cmake b/Modules/private/CreateCoverageTargets.cmake index 57ea2131..b0c77c3d 100644 --- a/Modules/private/CreateCoverageTargets.cmake +++ b/Modules/private/CreateCoverageTargets.cmake @@ -27,8 +27,8 @@ find_program(LCOV_EXECUTABLE lcov) find_program(GENHTML_EXECUTABLE genhtml) find_program(GCOVR_EXECUTABLE gcovr) -# Find Python3 and normalization scripts -find_package(Python3 COMPONENTS Interpreter) +# Find Python and normalization scripts +find_package(Python COMPONENTS Interpreter) # Find CTest coverage tool find_program( diff --git a/plugins/python/CMakeLists.txt b/plugins/python/CMakeLists.txt index f43e12c9..c1471fe2 100644 --- a/plugins/python/CMakeLists.txt +++ b/plugins/python/CMakeLists.txt @@ -1,96 +1,28 @@ find_package( Python 3.12 - COMPONENTS Interpreter Development - QUIET + COMPONENTS Interpreter Development NumPy + REQUIRED ) -if(Python_FOUND) +if(Python_NumPy_VERSION VERSION_LESS "2.0.0") + message(FATAL_ERROR "NumPy version is too low: ${Python_NumPy_VERSION} found, at least 2.0.0 required") +endif() - # Verify installation of necessary python modules for specific tests - - function(check_python_module_version MODULE_NAME MIN_VERSION OUT_VAR) - execute_process( - COMMAND - ${Python_EXECUTABLE} -c "import sys -try: - import ${MODULE_NAME} - from packaging.version import parse as parse_version - installed_version = getattr(${MODULE_NAME}, '__version__', None) - if parse_version(installed_version) >= parse_version('${MIN_VERSION}'): - sys.exit(0) - else: - sys.exit(2) # Version too low -except ImportError: - sys.exit(1)" - RESULT_VARIABLE _module_check_result - ) - - if(_module_check_result EQUAL 0) - set(${OUT_VAR} - TRUE - PARENT_SCOPE - ) - elseif(_module_check_result EQUAL 1) - set(${OUT_VAR} - FALSE - PARENT_SCOPE - ) # silent b/c common - elseif(_module_check_result EQUAL 2) - message( - WARNING - "Python module '${MODULE_NAME}' found but version too low (min required: ${MIN_VERSION})." - ) - set(${OUT_VAR} - FALSE - PARENT_SCOPE - ) - else() - message( - WARNING "Unknown error while checking Python module '${MODULE_NAME}'." - ) - set(${OUT_VAR} - FALSE - PARENT_SCOPE - ) - endif() - endfunction() - - check_python_module_version("numpy" "2.0.0" HAS_NUMPY) - - # Phlex module to run Python algorithms - add_library( - pymodule MODULE src/pymodule.cpp src/modulewrap.cpp src/configwrap.cpp - src/lifelinewrap.cpp src/errorwrap.cpp - ) - include_directories(pymodule, ${Python_INCLUDE_DIRS}) - target_link_libraries( - pymodule - PRIVATE phlex::module ${Python_LIBRARIES} - PUBLIC Python::Python - ) - - install(TARGETS pymodule LIBRARY DESTINATION lib) - - # numpy support if installed - if(HAS_NUMPY) - - # locate numpy's header directory - execute_process( - COMMAND "${Python_EXECUTABLE}" -c - "import numpy; print(numpy.get_include(), end='')" - RESULT_VARIABLE NUMPY_RESULT - OUTPUT_VARIABLE NUMPY_INCLUDE_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE - ) +# Phlex module to run Python algorithms +add_library( + pymodule MODULE src/pymodule.cpp src/modulewrap.cpp src/configwrap.cpp + src/lifelinewrap.cpp src/errorwrap.cpp + ) - if(NUMPY_RESULT EQUAL 0) - include_directories(pymodule PRIVATE ${NUMPY_INCLUDE_DIR}) - target_compile_definitions( - pymodule PRIVATE PHLEX_HAVE_NUMPY=1 - NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION - ) - endif() +target_link_libraries( + pymodule + PRIVATE phlex::module + Python::Python Python::NumPy + ) - endif() +target_compile_definitions( + pymodule PRIVATE PHLEX_HAVE_NUMPY=1 + NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + ) -endif() # Python available +install(TARGETS pymodule LIBRARY DESTINATION lib) From e69700afc6004fa20bf9e6c8487f27882b355e8e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 23 Dec 2025 17:22:23 +0000 Subject: [PATCH 2/2] Apply cmake-format fixes --- plugins/python/CMakeLists.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/python/CMakeLists.txt b/plugins/python/CMakeLists.txt index c1471fe2..81cb3ec9 100644 --- a/plugins/python/CMakeLists.txt +++ b/plugins/python/CMakeLists.txt @@ -5,24 +5,24 @@ find_package( ) if(Python_NumPy_VERSION VERSION_LESS "2.0.0") - message(FATAL_ERROR "NumPy version is too low: ${Python_NumPy_VERSION} found, at least 2.0.0 required") + message( + FATAL_ERROR + "NumPy version is too low: ${Python_NumPy_VERSION} found, at least 2.0.0 required" + ) endif() # Phlex module to run Python algorithms add_library( pymodule MODULE src/pymodule.cpp src/modulewrap.cpp src/configwrap.cpp - src/lifelinewrap.cpp src/errorwrap.cpp + src/lifelinewrap.cpp src/errorwrap.cpp ) target_link_libraries( - pymodule - PRIVATE phlex::module - Python::Python Python::NumPy + pymodule PRIVATE phlex::module Python::Python Python::NumPy ) target_compile_definitions( - pymodule PRIVATE PHLEX_HAVE_NUMPY=1 - NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + pymodule PRIVATE PHLEX_HAVE_NUMPY=1 NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION ) install(TARGETS pymodule LIBRARY DESTINATION lib)