Skip to content

Commit

Permalink
Trac #19104: Parse sage-spkg options in sage-spkg
Browse files Browse the repository at this point in the history
Instead of parsing the options to `sage -i` both in `src/bin/sage` and
in `sage-spkg`, parse them just in `sage-spkg` (without requiring a
specific order).

URL: http://trac.sagemath.org/19104
Reported by: jdemeyer
Ticket author(s): Jeroen Demeyer
Reviewer(s): Volker Braun
  • Loading branch information
Release Manager authored and vbraun committed Sep 6, 2015
2 parents 1155fbd + 4eb1aa8 commit 81e09c3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 49 deletions.
50 changes: 21 additions & 29 deletions build/bin/sage-spkg
Original file line number Diff line number Diff line change
Expand Up @@ -175,38 +175,30 @@ if [ $# -eq 0 ]; then
exit 0
fi

# Options have to come in a specific order,
# this is ensured by spkg/bin/sage.
# Parse options
INFO=0
if [ "$1" = '--info' ]; then
INFO=1
shift
fi

FORCE=0
if [ "$1" = '-f' ]; then
FORCE=1
while true; do
case "$1" in
--info)
INFO=1;;
-f)
FORCE=1;;
-d)
SAGE_INSTALL_FETCH_ONLY=1;;
-s)
export SAGE_KEEP_BUILT_SPKGS=yes;;
-c|--check)
SAGE_CHECK_PACKAGES=x # nonempty, so not set to '!python' later
export SAGE_CHECK=yes;;
-*)
echo >&2 "Error: unknown option '$1'"
exit 2;;
*) break;;
esac
shift
fi

DOWNLOAD_ONLY=0
if [ "$1" = '-d' ]; then
DOWNLOAD_ONLY=1
shift
elif [ -n "$SAGE_INSTALL_FETCH_ONLY" ]; then
DOWNLOAD_ONLY=1
fi
done

if [ "$1" = '-s' ]; then
export SAGE_KEEP_BUILT_SPKGS=yes
shift
fi

if [ "$1" = '-c' ]; then
export SAGE_CHECK=yes
SAGE_CHECK_PACKAGES=x # nonempty, so not set to '!python' later
shift
fi

##################################################################
# Figure out the package filename, download it if needed.
Expand Down Expand Up @@ -405,7 +397,7 @@ if [ -n "$SAGE_SPKG_COPY_UPSTREAM" ]; then
exit 1
fi
fi
if [ $DOWNLOAD_ONLY -ne 0 ]; then
if [ -n "$SAGE_INSTALL_FETCH_ONLY" ]; then
exit 0
fi

Expand Down
24 changes: 6 additions & 18 deletions src/bin/sage
Original file line number Diff line number Diff line change
Expand Up @@ -771,35 +771,23 @@ fi
install() {
maybe_sage_location

mkdir -p "$SAGE_LOGS"
for PKG in "$@"
do
# Check for options
case "$PKG" in
-f) OPTF="-f"
continue;;
-m) OPTS="-s"
echo >&2 "Warning: the -m option is deprecated since Sage 5.0. Use -s instead."
continue;;
-s) OPTS="-s"
continue;;
-c) OPTC="-c"
continue;;
--check) OPTC="-c"
continue;;
-info) OPTINFO="--info"
continue;;
--info) OPTINFO="--info"
continue;;
-*) echo >&2 "Error: unknown option '$PKG'"
-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;;
esac

PKG_NAME=`echo "$PKG" | sed -e "s/\.spkg$//"`
PKG_NAME=`basename "$PKG_NAME"`

sage-logger \
"sage-spkg $OPTINFO $OPTF $OPTS $OPTC '$PKG'" "$SAGE_LOGS/$PKG_NAME.log"
"sage-spkg $INSTALL_OPTIONS '$PKG'" "$SAGE_LOGS/$PKG_NAME.log"
# Do not try to install further packages if one failed
if [ $? -ne 0 ]; then
exit 1
Expand Down
18 changes: 16 additions & 2 deletions src/sage/tests/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ def test_executable(args, input="", timeout=100.0, **kwds):
sage: ret
0
Test ``sage --info [packages]``, unless this is a binary (bdist)
distribution which doesn't ship spkgs::
Test ``sage --info [packages]`` and the equivalent
``sage -i --info --info [packages]`` (the doubling of ``--info``
is intentional, that option should be idempotent)::
sage: out, err, ret = test_executable(["sage", "--info", "sqlite"])
sage: print out
Expand All @@ -214,6 +215,19 @@ def test_executable(args, input="", timeout=100.0, **kwds):
sage: ret
0
sage: out, err, ret = test_executable(["sage", "-i", "--info", "--info", "sqlite"])
sage: print out
Found local metadata for sqlite-...
= SQLite =
...
SQLite is a software library that implements a self-contained,
serverless, zero-configuration, transactional SQL database engine.
...
sage: err
''
sage: ret
0
Test ``sage-run`` on a Python file, both with an absolute and with a relative path::
sage: dir = tmp_dir(); name = 'python_test_file.py'
Expand Down

0 comments on commit 81e09c3

Please sign in to comment.