From e856a8e872282fe7f059900559f5e589f1b016aa Mon Sep 17 00:00:00 2001 From: Jeroen Demeyer Date: Thu, 27 Aug 2015 17:16:38 +0200 Subject: [PATCH] Change sage -i to install with dependencies --- build/bin/sage-spkg | 2 +- src/bin/sage | 80 +++++++++++++++++++++++++++++---------- src/sage/tests/cmdline.py | 4 +- 3 files changed, 63 insertions(+), 23 deletions(-) diff --git a/build/bin/sage-spkg b/build/bin/sage-spkg index bc4a7046bbe..c779de91081 100755 --- a/build/bin/sage-spkg +++ b/build/bin/sage-spkg @@ -60,7 +60,7 @@ export LC_ALL=C usage() { cat < +Usage: sage -p If is a URL, download and install it. If it is a file name, install it. Otherwise, search Sage's list of packages (see diff --git a/src/bin/sage b/src/bin/sage index fb6daf24c07..6bc09ef0ab3 100755 --- a/src/bin/sage +++ b/src/bin/sage @@ -122,14 +122,15 @@ usage_advanced() { echo " -experimental -- list all experimental packages that can be installed" echo " -f [opts] [packages]-- shortcut for -i -f: force build of the given Sage" echo " packages" - echo " -i [opts] [packages]-- install the given Sage packages (unless they are" - echo " already installed); if no packages are given, print" - echo " a list of all installed packages. Options:" + echo " -i [opts] [packages]-- install the given Sage packages. Options:" echo " -c -- run the packages' test suites" echo " -f -- force build: install the packages even" echo " if they are already installed" - echo " -s -- do not delete the spkg/build directories" + echo " -s -- do not delete the temporary build directories" echo " after a successful build" + echo " -d -- only download, do not install packages" + echo " -p [opts] [packages]-- like -i but without dependency checking and with" + echo " support for old-style spkgs" echo " -info [packages] -- print the SPKG.txt of the given packages" echo " --location -- if needed, fix paths to make Sage relocatable" echo " -optional -- list all optional packages that can be installed" @@ -272,10 +273,62 @@ if [ "$1" = '-upgrade' -o "$1" = "--upgrade" ]; then exec local/bin/sage-upgrade "$@" fi +# Check for '-i' before sourcing sage-env: running "make" +# should be run outside of the Sage shell. +if [ "$1" = '-f' ]; then + # -f is an alias for -i -f + set -- -i "$@" +fi + +if [ "$1" = '-i' ]; then + shift + if [ -z "$MAKE" ]; then + MAKE="make" + fi + + set -e + + cd "$SAGE_ROOT" + # First of all, make sure that the toolchain is up-to-date + # (which is a dependency of every package) + ./sage --location + $MAKE all-toolchain + echo + + INSTALL_OPTIONS="-f" # Options to sage-spkg + for PKG in "$@" + do + case "$PKG" in + -info|--info) + echo >&2 "Error: 'sage -i $PKG ' is no longer supported, use 'sage --info ' instead." + exit 2;; + -f) FORCE_INSTALL=yes;; + -*) INSTALL_OPTIONS="$INSTALL_OPTIONS $PKG";; + *) + if [ x$FORCE_INSTALL = xyes ]; then + rm -f "local/var/lib/sage/installed/$PKG"-* + fi + # First check that $PKG is actually a Makefile target + if ! grep "^$PKG: " build/make/Makefile >/dev/null; then + echo >&2 "Error: package '$PKG' not found" + echo >&2 "Assuming it is an old-style package... (this is deprecated: use -p instead of -i to install old-style packages)" + sleep 5 + ./sage -p $INSTALL_OPTIONS "$PKG" + else + $MAKE SAGE_SPKG="sage-spkg $INSTALL_OPTIONS" "$PKG" + fi;; + esac + done + exit 0 +fi + + +##################################################################### # Source sage-env ($0 is the name of this "sage" script, so we can just # append -env to that). We redirect stdout to stderr, which is safer # for scripts. +##################################################################### . "$0-env" >&2 if [ $? -ne 0 ]; then echo >&2 "Error setting environment variables by sourcing '$0-env';" @@ -768,9 +821,6 @@ install() { do # Check for options case "$PKG" in - -info) - echo >&2 "Error: 'sage -i -info ' is no longer supported, use 'sage --info ' instead." - exit 2;; -*) INSTALL_OPTIONS="$INSTALL_OPTIONS $PKG" continue;; @@ -797,6 +847,7 @@ install() { exit 0 } + if [ "$1" = '-package' -o "$1" = "--package" ]; then shift exec sage-package $@ @@ -822,26 +873,15 @@ if [ "$1" = '-installed' -o "$1" = "--installed" ]; then exec sage-list-packages installed $@ fi -if [ "$1" = '-i' ]; then +if [ "$1" = '-p' ]; then shift - # If there are no further arguments, simply list all installed - # packages. + # If there are no further arguments, display usage help. if [ $# -eq 0 ]; then exec sage-spkg fi install "$@" fi -if [ "$1" = '-f' ]; then - shift - # If there are no further arguments, simply list all installed - # packages. - if [ $# -eq 0 ]; then - exec sage-spkg - fi - install -f "$@" -fi - if [ "$1" = '-info' -o "$1" = '--info' ]; then shift for PKG in "$@" diff --git a/src/sage/tests/cmdline.py b/src/sage/tests/cmdline.py index a1a9b4e8a6d..0666d7b6ab3 100644 --- a/src/sage/tests/cmdline.py +++ b/src/sage/tests/cmdline.py @@ -200,7 +200,7 @@ def test_executable(args, input="", timeout=100.0, **kwds): 0 Test ``sage --info [packages]`` and the equivalent - ``sage -i --info --info [packages]`` (the doubling of ``--info`` + ``sage -p --info --info [packages]`` (the doubling of ``--info`` is intentional, that option should be idempotent):: sage: out, err, ret = test_executable(["sage", "--info", "sqlite"]) @@ -216,7 +216,7 @@ def test_executable(args, input="", timeout=100.0, **kwds): sage: ret 0 - sage: out, err, ret = test_executable(["sage", "-i", "--info", "--info", "sqlite"]) + sage: out, err, ret = test_executable(["sage", "-p", "--info", "--info", "sqlite"]) sage: print out Found local metadata for sqlite-... = SQLite =