diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 07850a30..8bf1f50a 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -12,17 +12,41 @@ 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 [[ - execute_process( - COMMAND "${Python3_EXECUTABLE}" -m pip install --no-deps --break-system-packages "${CMAKE_CURRENT_BINARY_DIR}" - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - OUTPUT_VARIABLE _pip_output - ERROR_VARIABLE _pip_output - RESULT_VARIABLE _pip_result) - message(STATUS ${_pip_output}) - if(NOT _pip_result EQUAL 0) - message(FATAL_ERROR "pip install failed with code ${_pip_result}") + # 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() + else() + message(WARNING "Command failed with code ${_pip_result}") + message(WARNING "Output: ${_pip_output}") + message(WARNING "Error: ${_pip_error}") + 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) diff --git a/python/pyproject.toml b/python/pyproject.toml index 76f70ed3..f8936c8a 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools", "wheel", "Cython", "build"] +requires = ["setuptools", "wheel", "Cython"] build-backend = "setuptools.build_meta" [tool.cibuildwheel]