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

Commit 8aa6fd9

Browse files
author
Matthias Koeppe
committed
build/bin/sage-dist-helpers (sdh_pip_install): Build a wheel, store it
1 parent 5ec24db commit 8aa6fd9

File tree

4 files changed

+91
-61
lines changed

4 files changed

+91
-61
lines changed

build/bin/sage-dist-helpers

+24-3
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,31 @@ sdh_pip_install() {
210210
local sudo="$SAGE_SUDO"
211211
local root=""
212212
fi
213-
$sudo sage-pip-install $root "$@" || \
214-
sdh_die "Error installing $PKG_NAME"
215-
}
213+
$sudo sage-pip-uninstall "$@" || \
214+
sdh_die "Error uninstalling a previous version of $PKG_NAME"
215+
216+
sage-python23 -m pip wheel --wheel-dir=. --no-binary :all: --verbose --no-deps --no-index --isolated --no-build-isolation "$@" || \
217+
sdh_die "Error building a wheel for $PKG_NAME"
216218

219+
wheel=""
220+
for w in *.whl; do
221+
if [ -n "$wheel" ]; then
222+
sdh_die "Error: more than one wheel found after building"
223+
fi
224+
if [ -f "$w" ]; then
225+
wheel="$w"
226+
fi
227+
done
228+
if [ -z "$wheel" ]; then
229+
sdh_die "Error: no wheel found after building"
230+
fi
231+
232+
$sudo sage-pip-install $root "$wheel" || \
233+
sdh_die "Error installing $wheel"
234+
mkdir -p "${SAGE_DESTDIR}${SAGE_SPKG_WHEELS}" && \
235+
mv "$wheel" "${SAGE_DESTDIR}${SAGE_SPKG_WHEELS}/" || \
236+
sdh_die "Error storing $wheel"
237+
}
217238

218239
sdh_cmake() {
219240
echo "Configuring $PKG_NAME with cmake"

build/bin/sage-pip-install

+4-58
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/usr/bin/env bash
2-
# This command is specifically for pip-installing from a local
3-
# source directory, as opposed to from a package index via package
4-
# name. That is, it is for pip-installing Sage spkgs from their
5-
# extracted upstream sources.
2+
# This command is specifically for pip-installing a previously
3+
# built wheel.
64
#
75
# This ensures that any previous installations of the same package
86
# are uninstalled first.
@@ -17,23 +15,7 @@
1715
# This also disables pip's version self-check.
1816
# --isolated : Don't read configuration files such as
1917
# ~/.pydistutils.cfg
20-
# --no-build-isolation:Build the package in the usual Python environment
21-
# (containing the dependencies) instead of an
22-
# "isolated" environment
23-
pip_install_flags="--ignore-installed --verbose --no-deps --no-index --isolated --no-build-isolation"
24-
25-
# Consume any additional pip install arguments except the last one
26-
while [ $# -gt 1 ]; do
27-
pip_install_flags="$pip_install_flags $1"
28-
shift
29-
done
30-
31-
# Last argument must be "." and will be ignored
32-
if [ "$1" != "." ]; then
33-
echo >&2 "$0 requires . as final argument"
34-
exit 1
35-
fi
36-
18+
pip_install_flags="--ignore-installed --verbose --no-deps --no-index --isolated"
3719

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

51-
52-
# Find out the name of the package that we are installing
53-
name="$($PYTHON setup.py --name)"
54-
55-
if [ $? -ne 0 ]; then
56-
echo >&2 "Error: could not determine package name"
57-
exit 1
58-
fi
59-
60-
if [ $(echo "$name" | wc -l) -gt 1 ]; then
61-
name="$(echo "$name" | tail -1)"
62-
echo >&2 "Warning: This package has a badly-behaved setup.py which outputs"
63-
echo >&2 "more than the package name for 'setup.py --name'; using the last"
64-
echo >&2 "line as the package name: $name"
65-
fi
66-
67-
6833
# We should avoid running pip2/3 while uninstalling a package because that
6934
# is prone to race conditions. Therefore, we use a lockfile while
7035
# running pip. This is implemented in the Python script sage-flock
7136
LOCK="$SAGE_LOCAL/var/lock/$PIP.lock"
7237

73-
# Keep uninstalling as long as it succeeds
74-
while true; do
75-
out=$(sage-flock -x $LOCK $PYTHON -m pip uninstall --disable-pip-version-check -y "$name" 2>&1)
76-
if [ $? -ne 0 ]; then
77-
# Uninstall failed
78-
echo >&2 "$out"
79-
exit 1
80-
fi
81-
82-
# Uninstall succeeded, which may mean that the package was not
83-
# installed to begin with.
84-
if [[ "$out" != *"not installed" ]]; then
85-
break
86-
fi
87-
done
88-
89-
9038
# Finally actually do the installation (the "SHARED" tells pip2/3-lock
9139
# to apply a shared lock)
92-
echo "Installing package $name using $PIP"
93-
94-
sage-flock -s $LOCK $PYTHON -m pip install $pip_install_flags .
40+
sage-flock -s $LOCK $PYTHON -m pip install $pip_install_flags "$@"
9541
if [ $? -ne 0 ]; then
9642
echo >&2 "Error: installing with $PIP failed"
9743
exit 3

build/bin/sage-pip-uninstall

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env bash
2+
# This command ensures that any previous installations of the same package
3+
# are uninstalled.
4+
5+
# Only argument must be "." and will be ignored.
6+
if [ $# -gt 1 ]; then
7+
echo >&2 "$0 requires . as only argument"
8+
exit 1
9+
fi
10+
if [ "$1" != "." ]; then
11+
echo >&2 "$0 requires . as final argument"
12+
exit 1
13+
fi
14+
15+
# Note: We need to take care to specify the full path to Sage's Python here
16+
# to emphasize that this command hould use it, and not the system Python;
17+
# see https://trac.sagemath.org/ticket/18438
18+
# But now we delegate this to sage-python23.
19+
PYTHON=sage-python23
20+
21+
# The PIP variable is only used to determine the name of the lock file.
22+
if [ "$SAGE_PYTHON3" = yes ]; then
23+
PIP=pip3
24+
else
25+
PIP=pip2
26+
fi
27+
28+
# Find out the name of the package that we are installing
29+
name="$($PYTHON setup.py --name)"
30+
31+
if [ $? -ne 0 ]; then
32+
echo >&2 "Error: could not determine package name"
33+
exit 1
34+
fi
35+
36+
if [ $(echo "$name" | wc -l) -gt 1 ]; then
37+
name="$(echo "$name" | tail -1)"
38+
echo >&2 "Warning: This package has a badly-behaved setup.py which outputs"
39+
echo >&2 "more than the package name for 'setup.py --name'; using the last"
40+
echo >&2 "line as the package name: $name"
41+
fi
42+
43+
# We should avoid running pip2/3 while uninstalling a package because that
44+
# is prone to race conditions. Therefore, we use a lockfile while
45+
# running pip. This is implemented in the Python script sage-flock
46+
LOCK="$SAGE_LOCAL/var/lock/$PIP.lock"
47+
48+
# Keep uninstalling as long as it succeeds
49+
while true; do
50+
out=$(sage-flock -x $LOCK $PYTHON -m pip uninstall --disable-pip-version-check -y "$name" 2>&1)
51+
if [ $? -ne 0 ]; then
52+
# Uninstall failed
53+
echo >&2 "$out"
54+
exit 1
55+
fi
56+
57+
# Uninstall succeeded, which may mean that the package was not
58+
# installed to begin with.
59+
if [[ "$out" != *"not installed" ]]; then
60+
break
61+
fi
62+
done

build/make/install

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export SAGE_PKGCONFIG="$SAGE_LOCAL/lib/pkgconfig"
2020
export SAGE_LOGS="$SAGE_ROOT/logs/pkgs"
2121
export SAGE_SPKG_INST="$SAGE_LOCAL/var/lib/sage/installed"
2222
export SAGE_SPKG_SCRIPTS="$SAGE_LOCAL/var/lib/sage/scripts"
23+
export SAGE_SPKG_WHEELS="$SAGE_LOCAL/var/lib/sage/wheels"
2324

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

0 commit comments

Comments
 (0)