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

Normal Python packages: postpone wheel installation to the post-install phase #36743

Merged
merged 5 commits into from
Dec 10, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -548,9 +548,13 @@ WRAPPED_SCRIPTS="build install check preinst postinst $INSTALLED_SCRIPTS"

# 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 @@ -706,10 +710,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 @@ -729,6 +734,15 @@ done


# 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