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

Commit

Permalink
Change sage -i to install with dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jdemeyer committed Aug 27, 2015
1 parent cb05746 commit e856a8e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 23 deletions.
2 changes: 1 addition & 1 deletion build/bin/sage-spkg
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export LC_ALL=C
usage()
{
cat <<EOF
Usage: sage -i <options> <package name>
Usage: sage -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
Expand Down
80 changes: 60 additions & 20 deletions src/bin/sage
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 <package>' is no longer supported, use 'sage --info <package>' 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';"
Expand Down Expand Up @@ -768,9 +821,6 @@ install() {
do
# Check for options
case "$PKG" in
-info)
echo >&2 "Error: 'sage -i -info <package>' is no longer supported, use 'sage --info <package>' instead."
exit 2;;
-*)
INSTALL_OPTIONS="$INSTALL_OPTIONS $PKG"
continue;;
Expand All @@ -797,6 +847,7 @@ install() {
exit 0
}


if [ "$1" = '-package' -o "$1" = "--package" ]; then
shift
exec sage-package $@
Expand All @@ -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 "$@"
Expand Down
4 changes: 2 additions & 2 deletions src/sage/tests/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand All @@ -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 =
Expand Down

0 comments on commit e856a8e

Please sign in to comment.