Skip to content

Commit c4f35cf

Browse files
author
Release Manager
committedMay 22, 2022
Trac #33786: Top-level sage script: Unconditionally set SAGE_ROOT
This will make it more robust when accidentally invoked from a sage shell inside another Sage installation. Related to https://groups.google.com/g/sage- release/c/GOGWk66zaCQ/m/0o9KtVDIAAAJ URL: https://trac.sagemath.org/33786 Reported by: mkoeppe Ticket author(s): Matthias Koeppe Reviewer(s): John Palmieri
2 parents 83a89a0 + 01caa38 commit c4f35cf

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed
 

‎sage

+15-15
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,15 @@
1717
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1818

1919

20-
# Set SAGE_ROOT to the location of the sage install, i.e. the directory
21-
# containing this shell script. If unset, we will try to figure it out
22-
# automatically.
23-
#SAGE_ROOT=/path/to/sage-version
24-
2520
# Resolve all symbolic links in a filename. This more or less behaves
2621
# like "readlink -f" except that it does not convert the filename to an
2722
# absolute path (a relative path remains relative), nor does it treat
2823
# "." or ".." specially.
2924
#
3025
# WARNING: this function is copy/pasted from src/bin/sage-env, and
31-
# deserves to be factored out at some point in the future. In the
32-
# meantime however the two should be kept synchronized.
26+
# would deserve to be factored out if we could -- but we need it here so
27+
# we can actually find other files in SAGE_ROOT!
28+
# The copies should be kept synchronized.
3329
resolvelinks() {
3430
# $in is what still needs to be converted (normally has no starting slash)
3531
in="$1"
@@ -104,16 +100,20 @@ resolvelinks() {
104100
echo "$out"
105101
}
106102

107-
# If SAGE_ROOT is not given, find it out from $0
108-
if [ -z "$SAGE_ROOT" ]; then
109-
# Get the path to $0 (this shell script) with all symbolic links
110-
# resolved
111-
SAGE_ROOT=`resolvelinks "$0"` || \
103+
# Determine SAGE_ROOT from $0. This is so we can find the src/bin/sage script.
104+
#
105+
# This uses "resolvelinks" to support the use case of symlinking this script
106+
# into a directory that is in PATH, which was longstanding recommended practice.
107+
#
108+
# (The updated README.md and installation manual from Trac #33787 recommend to
109+
# symlink the installed version of the src/bin/sage script instead.)
110+
111+
# Get the path to $0 (this shell script) with all symbolic links resolved
112+
SAGE_ROOT=`resolvelinks "$0"` || \
112113
SAGE_ROOT="$0"
113114

114-
# Get the directory component
115-
SAGE_ROOT="${SAGE_ROOT%/*}"
116-
fi
115+
# Get the directory component
116+
SAGE_ROOT="${SAGE_ROOT%/*}"
117117

118118
# Make SAGE_ROOT absolute
119119
SAGE_ROOT=`cd "$SAGE_ROOT" && pwd -P`

0 commit comments

Comments
 (0)
Please sign in to comment.