Skip to content

Commit

Permalink
sagemathgh-36743: Normal Python packages: postpone wheel installation…
Browse files Browse the repository at this point in the history
… to the post-install phase

    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes sagemath#1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->

Previously, on `sdh_pip_install`, the wheel file is staged in DESTDIR,
but the wheel is installed immediately.
Now we store a new script `spkg-pipinst`, which is run after unloading
DESTDIR (and before any `spkg-postinst` script), which does the actual
installation of the wheel.

- This resolves sagemath#30956 (fixing the wheel URLs shown in `sage -pip
freeze`) -- except when `SAGE_SUDO` is set.

Apart from this and some changes to the messages displayed during
package installation, this should make no difference for any of our
packages.

Just so that it is tested for at least one package in CI, we include a
small package update.

Together with
- sagemath#36738 and
- sagemath#36740,

this is preparation for requiring only the build dependencies ("build-
system requires") while building a wheel for the package, and to require
the runtime dependencies ("install-requires") only later, when the wheel
is to be installed.

<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36743
Reported by: Matthias Köppe
Reviewer(s): John H. Palmieri
  • Loading branch information
Release Manager committed Dec 9, 2023
2 parents 46b03d5 + f981b15 commit abb1a51
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 23 deletions.
50 changes: 35 additions & 15 deletions build/bin/sage-dist-helpers
Original file line number Diff line number Diff line change
Expand Up @@ -355,38 +355,58 @@ sdh_store_and_pip_install_wheel() {
shift
done
sdh_store_wheel "$@"
if [ -n "$SAGE_SUDO" ]; then
# Trac #29585: Do the SAGE_DESTDIR staging of the wheel installation
# ONLY if SAGE_SUDO is set (in that case, we still do the staging so
# that we do not invoke pip as root).

wheel_basename="${wheel##*/}"
distname="${wheel_basename%%-*}"

if [ -d "$SAGE_BUILD_DIR/$PKG_NAME" ]; then
# Normal package install through sage-spkg;
# scripts live in the package's build directory
# until copied to the final destination by sage-spkg.
script_dir="$SAGE_BUILD_DIR/$PKG_NAME"
else
script_dir="$SAGE_SPKG_SCRIPTS/$PKG_BASE"
fi

if [ -n "$SAGE_DESTDIR" -a -z "$SAGE_SUDO" ]; then
# We stage the wheel file and do the actual installation in post.
echo "sdh_actually_pip_install_wheel $distname $pip_options -r \"\$SAGE_SPKG_SCRIPTS/\$PKG_BASE/spkg-requirements.txt\"" >> "$script_dir"/spkg-pipinst
else
if [ -n "$SAGE_DESTDIR" ]; then
# Trac #29585: Do the SAGE_DESTDIR staging of the wheel installation
# ONLY if SAGE_SUDO is set (in that case, we still do the staging so
# that we do not invoke pip as root).
# --no-warn-script-location: Suppress a warning caused by --root
local sudo=""
local root="--root=$SAGE_DESTDIR --no-warn-script-location"
else
# Trac #32361: Of course, this can only be done for normal packages,
# whose installation goes through sage-spkg.
# For script packages, we do have to invoke pip as root.
elif [ -n "$SAGE_SUDO" ]; then
# Trac #32361: For script packages, we do have to invoke pip as root.
local sudo="$SAGE_SUDO"
local root=""
else
#
local sudo=""
local root=""
fi
else
local sudo=""
local root=""
sdh_actually_pip_install_wheel $distname $root $pip_options "$wheel"
fi
echo "sdh_pip_uninstall -r \"\$SAGE_SPKG_SCRIPTS/\$PKG_BASE/spkg-requirements.txt\"" >> "$script_dir"/spkg-piprm
}

sdh_actually_pip_install_wheel() {
distname=$1
shift
# Trac #32659: pip no longer reinstalls local wheels if the version is the same.
# Because neither (1) applying patches nor (2) local changes (in the case
# of sage-conf, sage-setup, etc.) bump the version number, we need to
# override this behavior. The pip install option --force-reinstall does too
# much -- it also reinstalls all dependencies, which we do not want.
wheel_basename="${wheel##*/}"
distname="${wheel_basename%%-*}"
$sudo sage-pip-uninstall "$distname"
if [ $? -ne 0 ]; then
echo "(ignoring error)" >&2
fi
$sudo sage-pip-install $root $pip_options "$wheel" || \
sdh_die "Error installing ${wheel##*/}"
$sudo sage-pip-install "$@" || \
sdh_die "Error installing $distname"
}

sdh_pip_uninstall() {
Expand Down
22 changes: 18 additions & 4 deletions build/bin/sage-spkg
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,13 @@ __EOF__

# Prepare script for uninstallation of packages that use sdh_pip_install
# or sdh_store_and_pip_install_wheel.
echo 'sdh_pip_uninstall -r $SAGE_SPKG_SCRIPTS/$PKG_BASE/spkg-requirements.txt' > spkg-piprm.in
touch spkg-piprm.in

for script in $WRAPPED_SCRIPTS; do
# Prepare script for deferred installation of packages that use sdh_pip_install
# or sdh_store_and_pip_install_wheel.
touch spkg-pipinst.in

for script in $WRAPPED_SCRIPTS pipinst; do # pipinst can be added to WRAPPED_SCRIPTS later
# 'Installed' scripts are not run immediately out of the package build
# directory, and may be run later, so set their root directory to
# $SAGE_ROOT
Expand Down Expand Up @@ -730,10 +734,11 @@ INSTALLED_SCRIPTS_DEST="$SAGE_SPKG_SCRIPTS/$PKG_BASE"

if [ ! -f $INSTALLED_SCRIPTS_DEST/spkg-requirements.txt ]; then
# No packages to uninstall with pip, so remove the prepared uninstall script
rm -f spkg-piprm spkg-piprm.in
# and the prepared deferred installation script
rm -f spkg-piprm spkg-piprm.in spkg-pipinst spkg-pipinst.in
fi

for script in $INSTALLED_SCRIPTS; do
for script in $INSTALLED_SCRIPTS pipinst; do # pipinst can be added to WRAPPED_SCRIPTS later
script="spkg-$script"

if [ -f "$script" ]; then
Expand All @@ -754,6 +759,15 @@ done

post_install() { #################################################
# Run the post-install script, if any
# But first complete the delayed installation of wheels.
if [ -f spkg-pipinst ]; then
echo "Running pip-install script for $PKG_NAME."
$SAGE_SUDO ./spkg-pipinst
if [ $? -ne 0 ]; then
error_msg "Error running the pipinst script for $PKG_NAME."
exit 1
fi
fi
if [ -f spkg-postinst ]; then
echo "Running post-install script for $PKG_NAME."
time $SAGE_SUDO ./spkg-postinst
Expand Down
5 changes: 5 additions & 0 deletions build/pkgs/pip/spkg-pipinst.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cd src

# 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"
6 changes: 3 additions & 3 deletions build/pkgs/texttable/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tarball=texttable-VERSION.tar.gz
sha1=25e1b92e02c8e919dc0da053efbe8c4874418a8d
md5=83eb15fb541dd857ff051a8d0c979b9c
cksum=3183998721
sha1=0fa175fa6e0fefea31434746641bedc8cbb60248
md5=e5d380c04fab132ccf0bbfd4f761bd51
cksum=274394355
upstream_url=https://pypi.io/packages/source/t/texttable/texttable-VERSION.tar.gz
2 changes: 1 addition & 1 deletion build/pkgs/texttable/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.6.7
1.7.0

0 comments on commit abb1a51

Please sign in to comment.