From 6bad52a02c1e1baad77b1a967092964b5f1e5b98 Mon Sep 17 00:00:00 2001 From: Matthew Feickert Date: Sun, 13 Mar 2022 19:05:04 -0500 Subject: [PATCH] [cmake] Add PIP_OPTIONS option for Python bindings install control Add CMake option PIP_OPTIONS to allow the user to pass in pip options at build configuration time to customize the Python bindings install. As '--verbose' is a pip option, this makes the PIP_VERBOSE CMake option added in PR 1586 redundant, and so it is removed. Additionally, as '--prefix' is also a pip option, append the selected default value of '$ENV{DESTDIR}/{CMAKE_INSTALL_PREFIX}' as a '--prefix' pip option if there is no '--prefix' given by the user. If there is a given '--prefix' from the user in PIP_OPTIONS already, warn the user that this might not be a good idea unless they know what they're doing. --- bindings/python/CMakeLists.txt | 22 +++++++++++++--------- cmake/XRootDDefaults.cmake | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt index d3781e25094..4d4ca1395eb 100644 --- a/bindings/python/CMakeLists.txt +++ b/bindings/python/CMakeLists.txt @@ -32,10 +32,17 @@ endif() configure_file(${SETUP_PY_IN} ${SETUP_PY}) -if( PIP_VERBOSE ) - set(PIP_INSTALL_VERBOSE_FLAG "--verbose") +SET(PIP_OPTIONS "" CACHE STRING "pip options used during the Python bindings install.") + +string(FIND "${PIP_OPTIONS}" "--prefix" PIP_OPTIONS_PREFIX_POSITION) +if( "${PIP_OPTIONS_PREFIX_POSITION}" EQUAL "-1" ) + string(APPEND PIP_OPTIONS " --prefix \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}") else() - set(PIP_INSTALL_VERBOSE_FLAG "") + message(WARNING + " The pip option --prefix has been set in '${PIP_OPTIONS}' which will change" + " it from its default value of '--prefix \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX}'." + " Make sure this is intentional and that you understand the effects." + ) endif() # Check it the Python interpreter has a valid version of pip @@ -59,7 +66,7 @@ if ( NOT ${VALID_PIP_EXIT_CODE} EQUAL 0 ) # https://docs.python.org/3/install/#splitting-the-job-up add_custom_command(OUTPUT ${OUTPUT} - COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} ${PIP_INSTALL_VERBOSE_FLAG} build + COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} --verbose build DEPENDS ${DEPS}) add_custom_target(python_target ALL DEPENDS ${OUTPUT} XrdCl) @@ -79,21 +86,18 @@ if ( NOT ${VALID_PIP_EXIT_CODE} EQUAL 0 ) CODE "EXECUTE_PROCESS( COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} install \ - ${PIP_INSTALL_VERBOSE_FLAG} \ + --verbose \ --prefix \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX} \ ${DEB_INSTALL_ARGS} )" ) else() - # Use --force-reinstall to ensure a clean install if a rebuild needs to happen install( CODE "EXECUTE_PROCESS( COMMAND ${PYTHON_EXECUTABLE} -m pip install \ - ${PIP_INSTALL_VERBOSE_FLAG} \ - --force-reinstall \ - --prefix \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX} \ + ${PIP_OPTIONS} \ ${CMAKE_CURRENT_BINARY_DIR} )" ) diff --git a/cmake/XRootDDefaults.cmake b/cmake/XRootDDefaults.cmake index 8ea736c5999..912173f2593 100644 --- a/cmake/XRootDDefaults.cmake +++ b/cmake/XRootDDefaults.cmake @@ -18,7 +18,7 @@ option( ENABLE_XRDCL "Enable XRootD client." option( ENABLE_TESTS "Enable unit tests." FALSE ) option( ENABLE_HTTP "Enable HTTP component." TRUE ) option( ENABLE_PYTHON "Enable python bindings." TRUE ) -option( PIP_VERBOSE "Turn on --verbose flag for pip during Python bindings install." FALSE ) +option( PIP_OPTIONS "pip options to use during the Python bindings install." "" ) option( XRDCL_ONLY "Build only the client and necessary dependencies" FALSE ) option( XRDCL_LIB_ONLY "Build only the client libraries and necessary dependencies" FALSE ) option( PYPI_BUILD "The project is being built for PyPI release" FALSE )