From cc5c148fc1d964f1b22a14541e1879a3f2891bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <> Date: Fri, 19 Sep 2025 00:41:18 -0400 Subject: [PATCH] python: repair python installation with cmake --- python/CMakeLists.txt | 59 ++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 8bf1f50a..2d9a0c19 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -12,41 +12,36 @@ add_custom_target(python DEPENDS opendht opendht_cpp.pxd opendht.pyx pyproject.toml ${CURRENT_SOURCE_DIR}/opendht/__init__.py ${CURRENT_SOURCE_DIR}/opendht/aio.py) -set(_pip_commands - "${Python3_EXECUTABLE};-m;pip;install;--no-deps;--break-system-packages;${CMAKE_CURRENT_BINARY_DIR}" - "${Python3_EXECUTABLE};-m;pip;install;--no-deps;${CMAKE_CURRENT_BINARY_DIR}" - "pip3;install;--no-deps;--break-system-packages;${CMAKE_CURRENT_BINARY_DIR}" - "pip;install;--no-deps;--break-system-packages;${CMAKE_CURRENT_BINARY_DIR}") - -install(CODE [[ - # Try different pip installation methods - - set(_success FALSE) - foreach(_cmd_list ${_pip_commands}) - string(REPLACE ";" " " _cmd_str "${_cmd_list}") - message(STATUS "Attempting: ${_cmd_str}") - - execute_process( - COMMAND ${_cmd_list} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - OUTPUT_VARIABLE _pip_output - ERROR_VARIABLE _pip_error - RESULT_VARIABLE _pip_result) - if(_pip_result EQUAL 0) - message(STATUS "Successfully installed Python package") - message(STATUS "Output: ${_pip_output}") - set(_success TRUE) - break() +install(CODE [[ + if(NOT Python3_EXECUTABLE) + find_package(Python3 COMPONENTS Interpreter) + endif() + if(NOT Python3_EXECUTABLE) + message(WARNING "Skipping Python package install: Python interpreter not found.") + else() + execute_process( + COMMAND ${Python3_EXECUTABLE} -m pip --version + OUTPUT_QUIET + ERROR_QUIET + RESULT_VARIABLE _pip_check) + if(NOT _pip_check EQUAL 0) + message(WARNING "Skipping Python package install: pip not available for ${Python3_EXECUTABLE}.") else() - message(WARNING "Command failed with code ${_pip_result}") - message(WARNING "Output: ${_pip_output}") - message(WARNING "Error: ${_pip_error}") + execute_process( + COMMAND ${Python3_EXECUTABLE} -m pip install --no-deps --break-system-packages . + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/python + OUTPUT_VARIABLE _pip_output + ERROR_VARIABLE _pip_error + RESULT_VARIABLE _pip_result) + + if(_pip_result EQUAL 0) + message(STATUS "Successfully installed Python package") + message(STATUS "Output: ${_pip_output}") + else() + message(WARNING "pip install failed (code: ${_pip_result})\nOutput: ${_pip_output}\nError: ${_pip_error}") + endif() endif() - endforeach() - - if(NOT _success) - message(FATAL_ERROR "All pip install attempts failed. Check that pip is available and the wheel was built correctly.") endif() ]]) if (OPENDHT_TOOLS)