Skip to content

Commit

Permalink
[cmake] Add PIP_OPTIONS option for Python bindings install control
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
matthewfeickert committed Mar 14, 2022
1 parent 3d64cda commit 7fbf2fe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 13 additions & 10 deletions bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -79,21 +86,17 @@ if ( NOT ${VALID_PIP_EXIT_CODE} EQUAL 0 )
CODE
"EXECUTE_PROCESS(
COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} install \
${PIP_INSTALL_VERBOSE_FLAG} \
--prefix \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX} \
--verbose \
${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}
)"
)
Expand Down
2 changes: 1 addition & 1 deletion cmake/XRootDDefaults.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down

0 comments on commit 7fbf2fe

Please sign in to comment.