Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
build/bin/sage-dist-helpers (sdh_pip_install): Build a wheel, store it
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Sep 8, 2020
1 parent 5ec24db commit 8aa6fd9
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 61 deletions.
27 changes: 24 additions & 3 deletions build/bin/sage-dist-helpers
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,31 @@ sdh_pip_install() {
local sudo="$SAGE_SUDO"
local root=""
fi
$sudo sage-pip-install $root "$@" || \
sdh_die "Error installing $PKG_NAME"
}
$sudo sage-pip-uninstall "$@" || \
sdh_die "Error uninstalling a previous version of $PKG_NAME"

sage-python23 -m pip wheel --wheel-dir=. --no-binary :all: --verbose --no-deps --no-index --isolated --no-build-isolation "$@" || \
sdh_die "Error building a wheel for $PKG_NAME"

wheel=""
for w in *.whl; do
if [ -n "$wheel" ]; then
sdh_die "Error: more than one wheel found after building"
fi
if [ -f "$w" ]; then
wheel="$w"
fi
done
if [ -z "$wheel" ]; then
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}" && \
mv "$wheel" "${SAGE_DESTDIR}${SAGE_SPKG_WHEELS}/" || \
sdh_die "Error storing $wheel"
}

sdh_cmake() {
echo "Configuring $PKG_NAME with cmake"
Expand Down
62 changes: 4 additions & 58 deletions build/bin/sage-pip-install
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env bash
# This command is specifically for pip-installing from a local
# source directory, as opposed to from a package index via package
# name. That is, it is for pip-installing Sage spkgs from their
# extracted upstream sources.
# This command is specifically for pip-installing a previously
# built wheel.
#
# This ensures that any previous installations of the same package
# are uninstalled first.
Expand All @@ -17,23 +15,7 @@
# This also disables pip's version self-check.
# --isolated : Don't read configuration files such as
# ~/.pydistutils.cfg
# --no-build-isolation:Build the package in the usual Python environment
# (containing the dependencies) instead of an
# "isolated" environment
pip_install_flags="--ignore-installed --verbose --no-deps --no-index --isolated --no-build-isolation"

# Consume any additional pip install arguments except the last one
while [ $# -gt 1 ]; do
pip_install_flags="$pip_install_flags $1"
shift
done

# Last argument must be "." and will be ignored
if [ "$1" != "." ]; then
echo >&2 "$0 requires . as final argument"
exit 1
fi

pip_install_flags="--ignore-installed --verbose --no-deps --no-index --isolated"

# Note: We need to take care to specify the full path to Sage's Python here
# to emphasize that this command hould use it, and not the system Python;
Expand All @@ -48,50 +30,14 @@ else
PIP=pip2
fi


# Find out the name of the package that we are installing
name="$($PYTHON setup.py --name)"

if [ $? -ne 0 ]; then
echo >&2 "Error: could not determine package name"
exit 1
fi

if [ $(echo "$name" | wc -l) -gt 1 ]; then
name="$(echo "$name" | tail -1)"
echo >&2 "Warning: This package has a badly-behaved setup.py which outputs"
echo >&2 "more than the package name for 'setup.py --name'; using the last"
echo >&2 "line as the package name: $name"
fi


# We should avoid running pip2/3 while uninstalling a package because that
# is prone to race conditions. Therefore, we use a lockfile while
# running pip. This is implemented in the Python script sage-flock
LOCK="$SAGE_LOCAL/var/lock/$PIP.lock"

# Keep uninstalling as long as it succeeds
while true; do
out=$(sage-flock -x $LOCK $PYTHON -m pip uninstall --disable-pip-version-check -y "$name" 2>&1)
if [ $? -ne 0 ]; then
# Uninstall failed
echo >&2 "$out"
exit 1
fi

# Uninstall succeeded, which may mean that the package was not
# installed to begin with.
if [[ "$out" != *"not installed" ]]; then
break
fi
done


# Finally actually do the installation (the "SHARED" tells pip2/3-lock
# to apply a shared lock)
echo "Installing package $name using $PIP"

sage-flock -s $LOCK $PYTHON -m pip install $pip_install_flags .
sage-flock -s $LOCK $PYTHON -m pip install $pip_install_flags "$@"
if [ $? -ne 0 ]; then
echo >&2 "Error: installing with $PIP failed"
exit 3
Expand Down
62 changes: 62 additions & 0 deletions build/bin/sage-pip-uninstall
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash
# This command ensures that any previous installations of the same package
# are uninstalled.

# Only argument must be "." and will be ignored.
if [ $# -gt 1 ]; then
echo >&2 "$0 requires . as only argument"
exit 1
fi
if [ "$1" != "." ]; then
echo >&2 "$0 requires . as final argument"
exit 1
fi

# Note: We need to take care to specify the full path to Sage's Python here
# to emphasize that this command hould use it, and not the system Python;
# see https://trac.sagemath.org/ticket/18438
# But now we delegate this to sage-python23.
PYTHON=sage-python23

# The PIP variable is only used to determine the name of the lock file.
if [ "$SAGE_PYTHON3" = yes ]; then
PIP=pip3
else
PIP=pip2
fi

# Find out the name of the package that we are installing
name="$($PYTHON setup.py --name)"

if [ $? -ne 0 ]; then
echo >&2 "Error: could not determine package name"
exit 1
fi

if [ $(echo "$name" | wc -l) -gt 1 ]; then
name="$(echo "$name" | tail -1)"
echo >&2 "Warning: This package has a badly-behaved setup.py which outputs"
echo >&2 "more than the package name for 'setup.py --name'; using the last"
echo >&2 "line as the package name: $name"
fi

# We should avoid running pip2/3 while uninstalling a package because that
# is prone to race conditions. Therefore, we use a lockfile while
# running pip. This is implemented in the Python script sage-flock
LOCK="$SAGE_LOCAL/var/lock/$PIP.lock"

# Keep uninstalling as long as it succeeds
while true; do
out=$(sage-flock -x $LOCK $PYTHON -m pip uninstall --disable-pip-version-check -y "$name" 2>&1)
if [ $? -ne 0 ]; then
# Uninstall failed
echo >&2 "$out"
exit 1
fi

# Uninstall succeeded, which may mean that the package was not
# installed to begin with.
if [[ "$out" != *"not installed" ]]; then
break
fi
done
1 change: 1 addition & 0 deletions build/make/install
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export SAGE_PKGCONFIG="$SAGE_LOCAL/lib/pkgconfig"
export SAGE_LOGS="$SAGE_ROOT/logs/pkgs"
export SAGE_SPKG_INST="$SAGE_LOCAL/var/lib/sage/installed"
export SAGE_SPKG_SCRIPTS="$SAGE_LOCAL/var/lib/sage/scripts"
export SAGE_SPKG_WHEELS="$SAGE_LOCAL/var/lib/sage/wheels"

if [ -z "${SAGE_ORIG_PATH_SET}" ]; then
SAGE_ORIG_PATH=$PATH && export SAGE_ORIG_PATH
Expand Down

0 comments on commit 8aa6fd9

Please sign in to comment.