Skip to content

Commit

Permalink
Trac #31045: pip, wheel, setuptools: Make wheels available in SAGE_SP…
Browse files Browse the repository at this point in the history
…KG_WHEELS

From #30913:

Currently, `pip`, `wheel`, and `setuptools` are installed without making
wheels available in `SAGE_SPKG_WHEELS`.

In this ticket, we make wheels available in `SAGE_SPKG_WHEELS`. For the
case of `setuptools`, we create a new spkg `setuptools_wheel` that takes
care of it (it depends on `wheel`).

This is so that after installation, we have a complete set of wheels for
all Python packages installed by the Sage distribution. This allows
users to create a venv by installing a compatible set of wheels (whose
compiled extensions use the configured libraries in `SAGE_LOCAL` and the
system). The most robust way of doing so is by disabling the use of PyPI
(`pip install --no-index`) so that no incompatible wheels can leak in.
(This can be tested using  #30913.)

As PEP 517 packages (packages with a `pyproject.toml`, such as `pplpy`)
are built using build isolation (without access to already installed
packages), they need access to their build system packages such as
`wheel` and `setuptools`. When use of PyPI is disabled, this relies on
distributions (either source or wheel) to be available otherwise. On
this ticket, we make them available as wheels. (We make `pip` available
as a wheel for completeness.)

URL: https://trac.sagemath.org/31045
Reported by: mkoeppe
Ticket author(s): Matthias Koeppe
Reviewer(s): John Palmieri
  • Loading branch information
Release Manager committed Mar 7, 2021
2 parents a7f0295 + 1d19802 commit 73cedf7
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 24 deletions.
24 changes: 17 additions & 7 deletions build/bin/sage-dist-helpers
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,14 @@ sdh_pip_install() {
sdh_store_and_pip_install_wheel .
}

sdh_store_and_pip_install_wheel() {
sdh_store_wheel() {
if [ -n "$SAGE_DESTDIR" ]; then
local sudo=""
# --no-warn-script-location: Suppress a warning caused by --root
local root="--root=$SAGE_DESTDIR --no-warn-script-location"
else
local sudo="$SAGE_SUDO"
local root=""
fi
if [ "$*" != "." ]; then
sdh_die "Error: sdh_store_and_pip_install_wheel requires . as only argument"
sdh_die "Error: sdh_store_wheel requires . as only argument"
fi
wheel=""
for w in dist/*.whl; do
Expand All @@ -252,11 +249,24 @@ sdh_store_and_pip_install_wheel() {
sdh_die "Error: no wheel found after building"
fi

$sudo sage-pip-install $root "$wheel" || \
sdh_die "Error installing $wheel"
mkdir -p "${SAGE_DESTDIR}${SAGE_SPKG_WHEELS}" && \
$sudo mv "$wheel" "${SAGE_DESTDIR}${SAGE_SPKG_WHEELS}/" || \
sdh_die "Error storing $wheel"
wheel="${SAGE_DESTDIR}${SAGE_SPKG_WHEELS}/${wheel##*/}"
}

sdh_store_and_pip_install_wheel() {
sdh_store_wheel "$@"
if [ -n "$SAGE_DESTDIR" ]; then
local sudo=""
# --no-warn-script-location: Suppress a warning caused by --root
local root="--root=$SAGE_DESTDIR --no-warn-script-location"
else
local sudo="$SAGE_SUDO"
local root=""
fi
$sudo sage-pip-install $root "$wheel" || \
sdh_die "Error installing ${wheel##*/}"
}

sdh_cmake() {
Expand Down
14 changes: 3 additions & 11 deletions build/pkgs/pip/spkg-install.in
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
cd src

sdh_setup_bdist_wheel

# pip can install itself! But first we need to ensure that the pip
# pip can install its own wheel! But first we need to ensure that the pip
# source directory in on the PYTHONPATH
export PYTHONPATH="$(pwd)/src"

# need to use --upgrade or --ignore-installed; Otherwise pip, which is
# importing itself, will think itself is already installed
#
versions=3

for vers in $versions; do
python${vers} -m pip install --verbose --no-index --ignore-installed \
--no-build-isolation --isolated --root="$SAGE_DESTDIR" . || \
sdh_die "Error building / installing pip${vers}"
done
sdh_store_and_pip_install_wheel .
5 changes: 5 additions & 0 deletions build/pkgs/setuptools_wheel/SPKG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
setuptools_wheel: Build the setuptools package as a wheel
=========================================================

After installing setuptools and wheel, we build a wheel of setuptools
to complete the set of wheels stored in our wheelhouse.
1 change: 1 addition & 0 deletions build/pkgs/setuptools_wheel/checksums.ini
5 changes: 5 additions & 0 deletions build/pkgs/setuptools_wheel/dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$(PYTHON) setuptools wheel

----------
All lines of this file are ignored except the first.
It is copied by SAGE_ROOT/build/make/install into SAGE_ROOT/build/make/Makefile.
1 change: 1 addition & 0 deletions build/pkgs/setuptools_wheel/install-requires.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# We use this file to mark the package as a Python package
1 change: 1 addition & 0 deletions build/pkgs/setuptools_wheel/package-version.txt
3 changes: 3 additions & 0 deletions build/pkgs/setuptools_wheel/spkg-install.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cd src
sdh_setup_bdist_wheel
sdh_store_wheel .
1 change: 1 addition & 0 deletions build/pkgs/setuptools_wheel/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
standard
16 changes: 10 additions & 6 deletions build/pkgs/wheel/spkg-install.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
cd src

versions=3
python3 setup.py --no-user-cfg install \
--single-version-externally-managed --root="$SAGE_DESTDIR" || \
sdh_die "Error building / installing package 'wheel'"

for vers in $versions; do
python${vers} setup.py --no-user-cfg install \
--single-version-externally-managed --root="$SAGE_DESTDIR" || \
sdh_die "Error building / installing wheel for Python ${vers}"
done
# Now build a wheel so that we have a complete set of wheels.

# Because of staging, we cannot use the installed 'wheel' package yet.
export PYTHONPATH="$(pwd)/src"

sdh_setup_bdist_wheel
sdh_store_wheel .

0 comments on commit 73cedf7

Please sign in to comment.