Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Install Python bindings with pip if available #1586

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ jobs:
-DCMAKE_INSTALL_PREFIX=/usr/local/ \
-DPYTHON_EXECUTABLE=$(command -v python3) \
-DENABLE_TESTS=ON \
-DPIP_VERBOSE=ON \
-S xrootd \
-B build
cmake3 build -LH
Expand Down Expand Up @@ -135,6 +136,7 @@ jobs:
-DCMAKE_INSTALL_PREFIX=/usr/local/ \
-DPYTHON_EXECUTABLE=$(command -v python3) \
-DENABLE_TESTS=ON \
-DPIP_VERBOSE=ON \
-S xrootd \
-B build
cmake3 build -LH
Expand Down Expand Up @@ -202,6 +204,7 @@ jobs:
-DCMAKE_INSTALL_PREFIX=/usr/ \
-DPYTHON_EXECUTABLE=$(command -v python2) \
-DENABLE_TESTS=ON \
-DPIP_VERBOSE=ON \
-S xrootd \
-B build
cmake3 build -LH
Expand Down
79 changes: 62 additions & 17 deletions bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,70 @@ endif()

configure_file(${SETUP_PY_IN} ${SETUP_PY})

add_custom_command(OUTPUT ${OUTPUT}
COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} build
DEPENDS ${DEPS})
if( PIP_VERBOSE )
set(PIP_INSTALL_VERBOSE_FLAG "--verbose")
else()
set(PIP_INSTALL_VERBOSE_FLAG "")
endif()

add_custom_target(python_target ALL DEPENDS ${OUTPUT} XrdCl)
# Check it the Python interpreter has a valid version of pip
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -m pip --version
RESULT_VARIABLE VALID_PIP_EXIT_CODE
OUTPUT_QUIET
)

# Get the distribution name on Debian families
execute_process( COMMAND grep -i ^NAME=\" /etc/os-release
OUTPUT_VARIABLE DEB_DISTRO )
STRING(REGEX REPLACE "^NAME=\"" "" DEB_DISTRO "${DEB_DISTRO}")
STRING(REGEX REPLACE "\".*" "" DEB_DISTRO "${DEB_DISTRO}")
if ( NOT ${VALID_PIP_EXIT_CODE} EQUAL 0 )
# Attempt to still install with deprecated invocation of setup.py
message(WARNING
" ${PYTHON_EXECUTABLE} does not have a valid pip associated with it."
" It is recommended that you install a version of pip to install Python"
" packages and bindings. If you are unable to install a version of pip"
" through a package manager or with your Python build try using the PyPA's"
" get-pip.py bootstrapping script ( https://github.com/pypa/get-pip ).\n"
" The installation of the Python bindings will attempt to continue using"
" the deprecated method of `${PYTHON_EXECUTABLE} setup.py install`."
)

if( DEB_DISTRO STREQUAL "Debian" OR DEB_DISTRO STREQUAL "Ubuntu" )
set(PYTHON_LAYOUT "unix" CACHE STRING "Python installation layout (deb or unix)")
set(DEB_INSTALL_ARGS "--install-layout ${PYTHON_LAYOUT}")
endif()
# 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
DEPENDS ${DEPS})

install(
CODE
"EXECUTE_PROCESS(
COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} install --prefix \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX} ${DEB_INSTALL_ARGS} --record PYTHON_INSTALLED)" )
add_custom_target(python_target ALL DEPENDS ${OUTPUT} XrdCl)

# Get the distribution name on Debian families
execute_process( COMMAND grep -i ^NAME= /etc/os-release
OUTPUT_VARIABLE DEB_DISTRO )
STRING(REGEX REPLACE "^NAME=\"" "" DEB_DISTRO "${DEB_DISTRO}")
STRING(REGEX REPLACE "\".*" "" DEB_DISTRO "${DEB_DISTRO}")

if( DEB_DISTRO STREQUAL "Debian" OR DEB_DISTRO STREQUAL "Ubuntu" )
set(PYTHON_LAYOUT "unix" CACHE STRING "Python installation layout (deb or unix)")
set(DEB_INSTALL_ARGS "--install-layout ${PYTHON_LAYOUT}")
endif()

install(
CODE
"EXECUTE_PROCESS(
COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} install \
${PIP_INSTALL_VERBOSE_FLAG} \
--prefix \$ENV{DESTDIR}/${CMAKE_INSTALL_PREFIX} \
${DEB_INSTALL_ARGS} \
--record PYTHON_INSTALLED
)"
)

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} \
${CMAKE_CURRENT_BINARY_DIR}
)"
)
endif()
1 change: 1 addition & 0 deletions cmake/XRootDDefaults.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +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( 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
1 change: 1 addition & 0 deletions packaging/rhel/xrootd.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ BuildRequires: libmacaroons-devel
BuildRequires: json-c-devel

%if %{python2only}
BuildRequires: python2-pip
BuildRequires: python2-devel
BuildRequires: python2-setuptools
%endif
Expand Down