Skip to content

Commit

Permalink
Trac #29852: sage: Determine SAGE_LOCAL, SAGE_ROOT via sage-config if…
Browse files Browse the repository at this point in the history
… it exists

We reduce the runtime dependency of `sage` on `sage-env-config`.

We query `sage-config` (installed by `sage_conf`, which has a dependency
on our `python3` package) for the values of `SAGE_LOCAL` and
`SAGE_ROOT`. `sage-config` must be in the same directory as $0.

This allows the installed `sage` script to be invoked directly from
`$SAGE_LOCAL/bin` in an environment without `SAGE_...` variables,
restoring what was previously implemented in #25486.

Also, we move sourcing of `sage-env-config` (but not `sage-env`!)
earlier in the `sage` script.
This is so that commands such as `$SAGE_LOCAL/bin/sage --root` work
correctly.

Follow-up tickets:
 - #30888 resolve symlinks so it even works for symlinks to
`$SAGE_LOCAL/bin/sage`
 - #30013 set `SAGE_VENV` too
 - remove the build-time dependency of the sage distribution on `src/bin
/sage-env-config`

URL: https://trac.sagemath.org/29852
Reported by: mkoeppe
Ticket author(s): Matthias Koeppe
Reviewer(s): Dima Pasechnik, François Bissey
  • Loading branch information
Release Manager committed Dec 13, 2020
2 parents c06aabc + eb3793e commit b997715
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/bin/sage
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ usage() {
# 'usage_advanced', which prints a longer help message, is defined
# below, after sourcing sage-env.

# Determine SAGE_ROOT and SAGE_LOCAL.
if [ -x "$0-config" ]; then
# optional sage-config console script, installed by sage_conf
export SAGE_ROOT=$("$0-config" SAGE_ROOT)
export SAGE_LOCAL=$("$0-config" SAGE_LOCAL)
fi
if [ -f "$0-env-config" ]; then
# As of Trac #22731, sage-env-config is optional.
. "$0-env-config" >&2
fi

#####################################################################
# Special options to be processed without sage-env
#####################################################################
Expand Down Expand Up @@ -188,10 +199,6 @@ fi
# append -env to that). We redirect stdout to stderr, which is safer
# for scripts.
#####################################################################
if [ -f "$0-env-config" ]; then
# As of Trac #22731, sage-env-config is optional.
. "$0-env-config" >&2
fi
if [ -f "$0-env" ]; then
. "$0-env" >&2
if [ $? -ne 0 ]; then
Expand Down

0 comments on commit b997715

Please sign in to comment.