Skip to content

Commit

Permalink
Trac #29289: Remove support for installing old-style SPKGs, deprecate…
Browse files Browse the repository at this point in the history
…d in Sage 6.9

Old-style SPKGs were deprecated in #19158, merged in Sage 6.9.

There is only sparse evidence of non-broken old-style SPKGs:

- `cunningham_tables` - https://groups.google.com/d/msg/sage-support
/T4IO-AmOsCM/HYy_N6UdAQAJ - added as new-style package in #29834

- `polytopes_db_4d` - added as new-style package in #26029

We remove support for old-style packages, but we keep the command `sage
-p`, which can also be used for installing a new-style package without
dependencies.

URL: https://trac.sagemath.org/29289
Reported by: mkoeppe
Ticket author(s): Matthias Koeppe, John Palmieri
Reviewer(s): Dima Pasechnik, John Palmieri, Matthias Koeppe
  • Loading branch information
Release Manager committed Jul 4, 2020
2 parents 95f468b + c0fb6d4 commit 10fb624
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 266 deletions.
312 changes: 54 additions & 258 deletions build/bin/sage-spkg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# sage-spkg: install a Sage package
#
# This script is typically invoked by giving the command
# sage -i <options> <package name>...
# sage {-i|-p} <options> <package name>...
#
# Options can be:
# -s: do not delete temporary build directory
Expand Down Expand Up @@ -75,12 +75,10 @@ export LC_ALL=C.UTF-8
usage()
{
cat <<EOF
Usage: sage -p <options> <package name>
Usage: sage {-i|-p} <options> <package name>
If <package name> is a URL, download and install it. If it is a file
name, install it. Otherwise, search Sage's list of packages (see
'sage --package list') for a matching package, and if a match is
found, install it.
Search Sage's list of packages (see 'sage --package list') for a
matching package, and if a match is found, install it.
Options:
-s: do not delete the temporary build directory
Expand Down Expand Up @@ -251,114 +249,71 @@ done
# Figure out the package filename, download it if needed.
##################################################################
# One should be able to install a package using
# sage -i <package-name> where <package-name> can be any of the
# following values:
#
# 1a. /path/to/<package>-x.y.z.spkg, i.e. the package is found somewhere
# in your file system and you're giving an absolute path.
# 1b. relative/path/to/<package>-x.y.z.spkg, the same with a relative
# path.
# 2a. <package>-x.y.z, i.e. the name of the package plus the package's
# version numbers.
# 2b. <package>-x.y.z.spkg, i.e. the name of the package in addition to
# the version numbers and the ".spkg" extension.
# 3. <package>, i.e. the name of the package without a version number.
# 4. <URL>/<package>-x.y.z.spkg, i.e. the full URL where the package
# is hosted. Any local packages matching <package> are ignored.
#
# In cases 2a, 2b and 3 we first look locally inside spkg/* for a
# matching package. Otherwise, we try to download it. In all cases,
# we reduce to case 1a.
#
# See #7544 and #12602.
#
# sage -i <package-name>

PKG_SRC="$1"
# Does PKG_SRC contain a slash?
if echo "$PKG_SRC" | grep / >/dev/null; then
PKG_HAS_PATH=yes
echo >&2 "Error: Installing old-style SPKGs is no longer supported"
exit 1
fi
# PKG_NAME is the last path component without .spkg
# This already reduces case 2b to case 2a.
PKG_NAME=`basename "$PKG_SRC" | sed 's/\.spkg$//'`
PKG_BASE=`echo "$PKG_NAME" | sed 's/-.*//'`
PKG_NAME="$PKG_SRC"
PKG_BASE=`echo "$PKG_NAME" | sed 's/-.*//'` # strip version number

# USE_LOCAL_SCRIPTS is a flag that if non-empty will cause
# this script to try to install the package using local metadata
# i.e. use upstream tarballs (vs spkgs) and scripts located in build/pkgs/$PKG_BASE
# the value of this flag is set in the next codeblock
USE_LOCAL_SCRIPTS=

if [ -f "$PKG_SRC" ]; then
# PKG_SRC is a file. If it is given by a relative path, prepend `pwd`
# (reduce case 1b to 1a)
if ! echo "$PKG_SRC" | grep '^/' >/dev/null; then
PKG_SRC="`pwd`/$PKG_SRC"
fi
elif [ -z "$PKG_HAS_PATH" ]; then
# If PKG_SRC is not an existing file and doesn't contain a slash,
# we are in case 2a or 3. If version in 2a matches the version in
# build/pkgs or we are in case 3 use the local scripts, otherwise
# we try to find a package in upstream
PKG_VER="${PKG_NAME#${PKG_BASE}}"
PKG_VER="${PKG_VER#-}"
PKG_SCRIPTS="$SAGE_ROOT/build/pkgs/$PKG_BASE"
LOCAL_PKG_VER=`cat $PKG_SCRIPTS/package-version.txt 2>/dev/null`
if [ -n "$LOCAL_PKG_VER" ] && [ -z "$PKG_VER" -o "$PKG_VER" = "$LOCAL_PKG_VER" ]; then
PKG_VER="$LOCAL_PKG_VER"
if [ -z "$PKG_VER" ]; then
PKG_NAME="${PKG_BASE}"
else
PKG_NAME="${PKG_BASE}-${PKG_VER}"
fi
USE_LOCAL_SCRIPTS=yes
PKG_BASE_VER=`echo $PKG_VER | sed 's/\.p[0-9][0-9]*$//'`
PKG_NAME_UPSTREAM=`lookup_param tarball "$PKG_SCRIPTS/checksums.ini" | sed "s/VERSION/$PKG_BASE_VER/"`
echo "Found local metadata for $PKG_NAME"

# Warning for experimental packages
if [ x`cat "$PKG_SCRIPTS/type"` = x"experimental" -a $INFO = 0 ]; then
if [ $YES != 1 ]; then
# We use /dev/tty here because our output may be redirected
# to a logfile, or line-buffered.
write_to_tty <<EOF
# PKG_SRC should look like "package-VERSION" or just "package".
# If VERSION matches the version in build/pkgs or there is no version
# specified, use the local scripts; otherwise we try to find a package
# in upstream.
PKG_VER="${PKG_NAME#${PKG_BASE}}"
PKG_VER="${PKG_VER#-}"
PKG_SCRIPTS="$SAGE_ROOT/build/pkgs/$PKG_BASE"
LOCAL_PKG_VER=`cat $PKG_SCRIPTS/package-version.txt 2>/dev/null`
PKG_VER="$LOCAL_PKG_VER"
if [ -z "$PKG_VER" ]; then
PKG_NAME="${PKG_BASE}"
else
PKG_NAME="${PKG_BASE}-${PKG_VER}"
fi
USE_LOCAL_SCRIPTS=yes
PKG_BASE_VER=`echo $PKG_VER | sed 's/\.p[0-9][0-9]*$//'`
PKG_NAME_UPSTREAM=`lookup_param tarball "$PKG_SCRIPTS/checksums.ini" | sed "s/VERSION/$PKG_BASE_VER/"`
echo "Found local metadata for $PKG_NAME"

# Warning for experimental packages
if [ x`cat "$PKG_SCRIPTS/type"` = x"experimental" -a $INFO = 0 ]; then
if [ $YES != 1 ]; then
# We use /dev/tty here because our output may be redirected
# to a logfile, or line-buffered.
write_to_tty <<EOF
=========================== WARNING ===========================
You are about to download and install the experimental package
$PKG_NAME. This probably won't work at all for you! There
is no guarantee that it will build correctly, or behave as
expected. Use at your own risk!
===============================================================
EOF
if [ $? -ne 0 ]; then
echo "Terminal not available for prompting. Use 'sage -i -y $PKG_BASE'"
echo "to install experimental packages in non-interactive mode."
YES=-1
fi
if [ $YES != -1 ]; then
read -p "Are you sure you want to continue [Y/n]? " answer < /dev/tty > /dev/tty 2>&1
else
answer=n
fi
case "$answer" in
n*|N*) exit 1;;
esac
# Confirm the user's input. (This gives important
# feedback to the user when output is redirected to a logfile.)
echo > /dev/tty "OK, installing $PKG_NAME now..."
fi
if [ $? -ne 0 ]; then
echo "Terminal not available for prompting. Use 'sage -i -y $PKG_BASE'"
echo "to install experimental packages in non-interactive mode."
YES=-1
fi

else
cd "$SAGE_DISTFILES"
for spkg in `ls -1t ${PKG_NAME}.spkg ${PKG_NAME}-*.spkg 2>/dev/null`; do
if [ -f "$spkg" ]; then
# Found a good package
echo "Found package $PKG_NAME in $SAGE_DISTFILES/$spkg"
PKG_SRC="`pwd`/$spkg"
PKG_NAME=`basename "$spkg" | sed 's/\.spkg$//'`
break
fi
done
if [ $YES != -1 ]; then
read -p "Are you sure you want to continue [Y/n]? " answer < /dev/tty > /dev/tty 2>&1
else
answer=n
fi
case "$answer" in
n*|N*) exit 1;;
esac
# Confirm the user's input. (This gives important
# feedback to the user when output is redirected to a logfile.)
echo > /dev/tty "OK, installing $PKG_NAME now..."
fi
fi

Expand All @@ -376,154 +331,8 @@ if [ ! -f "$PKG_SRC" ]; then
fi
PKG_SRC="$SAGE_DISTFILES/$PKG_NAME_UPSTREAM"
else
# Handle all the legacy cruft. This branch can be deleted once
# we get rid of old-style spkgs
if [ $YES = -1 ]; then
# User provided -n option, so don't even try to download the package"
echo "Old-style packages disabled by use of '-n' option"
exit 1
fi
if [ $INFO -eq 0 ]; then
echo "Attempting to download package $PKG_NAME"
else
echo "Attempting to get on-line info for package $PKG_NAME"
fi

# Reduce everything to case 4: full URL.
if [ -n "$PKG_HAS_PATH" ]; then
PKG_URL="$PKG_SRC"
else
# Handle cases 2a and 3, where the package name is something
# like "foo" or "foo-1.2.3".
MIRROR=$(sage-download-file --print-fastest-mirror)/spkg
if [ $? -ne 0 ]; then
error_msg "Error downloading list of packages"
exit 1
fi
for repo in optional experimental huge; do
# Download the list of packages.
echo ">>> Checking online list of $repo packages."
# File inside DOT_SAGE should be writable
repolist="${DOT_SAGE}/${repo}.list"
sage-download-file --quiet "$MIRROR/$repo/list" $repolist
if [ $? -ne 0 ]; then
rm -f $repolist
error_msg "Error downloading $MIRROR/$repo/list"
exit 1
fi

# The contrived sed commands print out either ${PKG_NAME} if
# it appears as a complete line or some string starting with
# ${PKG_NAME}- whichever occurs first.
# Tested with GNU sed, BSD sed (on OS X) and Solaris sed.
pkg=`sed -n -f <( echo "/^${PKG_NAME}\$/{p;q;}" && echo "/^${PKG_NAME}-/{p;q;}" ) $repolist`
rm -f $repolist
if [ -n "$pkg" ]; then
echo ">>> Found $pkg"
PKG_NAME=$pkg

# If INFO is set, try downloading only the .txt file
if [ $INFO -eq 1 ]; then
PKG_URL="$MIRROR/$repo/$pkg.txt"
sage-download-file --quiet "$PKG_URL" && exit 0
# If the download failed (for whatever reason),
# fall through and use the .spkg file.
else
if [ $YES != 1 ]; then
# Warn and ask the user if downloading an
# experimental package.
# Add a deprecation note for other packages,
# since old-style packages are deprecated.
if [ $repo = experimental ]; then
write_to_tty <<EOF
================================ WARNING =================================
You are about to download and install an unmaintained experimental
package. This probably won't work at all for you! There is no guarantee
that it will build correctly, or behave as expected. Use at your own risk!
This package will be removed in future versions of SageMath. If you care
about this package, you should make a proper new-style package instead.
For more information about making Sage packages, see
http://doc.sagemath.org/html/en/developer/packaging.html
==========================================================================
EOF
if [ $? -ne 0 ]; then
echo "Terminal not available for prompting. Use 'sage -i -y $PKG_BASE'"
echo "to install experimental packages in non-interactive mode."
YES=-1
fi
if [ $YES != -1 ]; then
read -p "Are you sure you want to continue [Y/n]? " answer < /dev/tty > /dev/tty 2>&1
else
answer=n
fi
case "$answer" in
n*|N*) exit 1;;
esac
else
# Deprecated since Sage 6.9, Trac #19158
write_to_tty <<EOF
================================== NOTE ==================================
You are about to download and install an old-style package. While this
might still work fine, old-style packages are unmaintained and deprecated.
This package will be removed in future versions of SageMath. If you care
about this package, you should make a proper new-style package instead.
For more information about making Sage packages, see
http://doc.sagemath.org/html/en/developer/packaging.html
==========================================================================
EOF
if [ $? = 0 -a $YES != -1 ]; then
read -t 30 -p "Are you sure (automatically continuing in 30 seconds) [Y/n]? " answer < /dev/tty > /dev/tty 2>&1
elif [ $YES = -1 ]; then
answer=n
else
answer=y
fi
case "$answer" in
n*|N*) exit 1;;
esac
fi
# Confirm the user's input. (This gives important
# feedback to the user when output is redirected to a logfile.)
echo > /dev/tty "OK, installing $PKG_NAME now..."
fi
fi
PKG_URL="$MIRROR/$repo/$pkg.spkg"
break
fi
done

if [ -z "$PKG_URL" ]; then
echo >&2 "Error: could not find a package matching $PKG_NAME"
echo >&2 " Try 'sage --package list' to see the available packages"
echo >&2 " $(sage-package apropos $PKG_NAME)"
exit 1
fi
fi

# Trac #5852: check write permissions
mkdir -p "$SAGE_DISTFILES"
if [ ! -w "$SAGE_DISTFILES" ]; then
error_msg "Error: no write access to packages directory $SAGE_PACKAGES"
exit 1
fi
cd "$SAGE_DISTFILES" || exit $?

# Download to a temporary file (such that we don't end up with a
# corrupted .spkg file).
PKG_TMP="${PKG_URL##*/}.tmp"
echo ">>> Trying to download $PKG_URL"
sage-download-file "$PKG_URL" "$PKG_TMP"
if [ $? -ne 0 ]; then
# Delete failed download
rm -f "$PKG_TMP"
error_msg "Error downloading $PKG_URL"
exit 1
fi

PKG_SRC="`pwd`/${PKG_URL##*/}"
mv -f "$PKG_TMP" "$PKG_SRC"
echo >&2 "Error: Installing old-style SPKGs is no longer supported"
exit 1
fi
fi

Expand Down Expand Up @@ -636,21 +445,8 @@ if [ "$USE_LOCAL_SCRIPTS" = yes ]; then
exit 1
fi
else
# Old-style package (deprecated)
echo "Extracting package $PKG_SRC"
ls -l "$PKG_SRC"

sage-uncompress-spkg "$PKG_SRC"
if [ $? -ne 0 ]; then
error_msg "Error: failed to extract $PKG_SRC"
exit 1
fi

cd "$PKG_NAME"
if [ $? -ne 0 ]; then
error_msg "Error: after extracting, the directory '$PKG_NAME' does not exist"
exit 1
fi
echo >&2 "Error: Installing old-style SPKGs is no longer supported."
exit 1
fi

echo "Finished extraction"
Expand Down Expand Up @@ -1049,4 +845,4 @@ fi
touch "$SAGE_LOCAL/lib/sage-force-relocate.txt"


echo "Finished installing $PKG_NAME.spkg"
echo "Finished installing $PKG_NAME"
Loading

0 comments on commit 10fb624

Please sign in to comment.