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

Commit

Permalink
Merge branch 't/22731/22731' into t/29852/get_rid_of_sage_env_config
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoeppe committed Nov 13, 2020
2 parents 2220595 + f3b7a9c commit 995af9f
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 113 deletions.
38 changes: 13 additions & 25 deletions src/bin/sage
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,11 @@ fi
# append -env to that). We redirect stdout to stderr, which is safer
# for scripts.
#####################################################################
if [ -f "$0-env-config" ] && [ -f "$0-env" ]; then
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
echo >&2 "Error setting environment variables by sourcing '$0-env';"
Expand Down Expand Up @@ -247,7 +250,7 @@ sage_setup() {
# if Python and sage-location haven't been installed yet.
maybe_sage_location()
{
if [ -w "$SAGE_LOCAL" ]; then
if [ -n "$SAGE_LOCAL" -a -w "$SAGE_LOCAL" ]; then
if [ -x "$SAGE_LOCAL/bin/python" ] && [ -x "$SAGE_LOCAL/bin/sage-location" ]; then
sage-location || exit $?
fi
Expand Down Expand Up @@ -517,39 +520,24 @@ fi
# Run Sage's versions of Python, pip, IPython, Jupyter.
#####################################################################

if [ "$1" = '-pip' -o "$1" = '--pip' ]; then
shift
exec sage-python -m pip "$@"
fi

if [ "$1" = '--pip3' ]; then
shift
exec "$SAGE_LOCAL"/bin/python3 -m pip "$@"
fi

if [ "$1" = '-python' -o "$1" = '--python' ]; then
shift
exec "$SAGE_LOCAL"/bin/python3 "$@"
fi

if [ "$1" = '-python3' -o "$1" = '--python3' ]; then
if [ "$1" = '-pip' -o "$1" = '--pip' -o "$1" = "--pip3" ]; then
shift
exec "$SAGE_LOCAL"/bin/python3 "$@"
exec python3 -m pip "$@"
fi

if [ "$1" = '-ipython' -o "$1" = '--ipython' ]; then
if [ "$1" = '-python' -o "$1" = '--python' -o "$1" = '-python3' -o "$1" = '--python3' ]; then
shift
exec "$SAGE_LOCAL"/bin/ipython "$@"
exec python3 "$@"
fi

if [ "$1" = '-ipython3' -o "$1" = '--ipython3' ]; then
if [ "$1" = '-ipython' -o "$1" = '--ipython' -o "$1" = '-ipython3' -o "$1" = '--ipython3' ]; then
shift
exec "$SAGE_LOCAL"/bin/ipython3 "$@"
exec ipython3 "$@"
fi

if [ "$1" = '-jupyter' -o "$1" = '--jupyter' ]; then
shift
exec "$SAGE_LOCAL"/bin/jupyter "$@"
exec jupyter "$@"
fi

#####################################################################
Expand Down Expand Up @@ -973,7 +961,7 @@ install() {
done
# Display a message if we actually installed something (using this
# file, generated by sage-spkg, is a bit of a hack though)
if [ -f "$SAGE_LOCAL/lib/sage-force-relocate.txt" ]; then
if [ -n "$SAGE_LOCAL" -a -f "$SAGE_LOCAL/lib/sage-force-relocate.txt" ]; then
echo
echo "Warning: it might be needed to update the Sage library before"
echo "installed packages work: you should run 'make' from \$SAGE_ROOT"
Expand Down
177 changes: 98 additions & 79 deletions src/bin/sage-env
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,6 @@
#
##########################################################################

if [ "${SAGE_ENV_CONFIG_SOURCED}" != 1 ]; then
# This script uses sage-env-config to find the ./configured value
# of SAGE_ROOT, but ironically, it doesn't know how to find
# sage-env-config because it doesn't know SAGE_ROOT yet!
# Fortunately, anyone that knows how to source sage-env must know
# how to source sage-env-config, so the issue is avoided by
# requiring sage-env-config to be sourced before sage-env.
echo 'must source sage-env-config before sage-env' >&2
return 3
fi

# Resolve all symbolic links in a filename. This more or less behaves
# like "readlink -f" except that it does not convert the filename to an
# absolute path (a relative path remains relative), nor does it treat
Expand Down Expand Up @@ -126,21 +115,18 @@ elif [ -f sage -a -d build ]; then
NEW_SAGE_ROOT="."
elif [ -f ../../sage -a -d ../../build ]; then
NEW_SAGE_ROOT="../.."
else
# No idea what SAGE_ROOT should be... it should have been set by sage-env-config.
echo >&2 "Error: You must set the SAGE_ROOT or SAGE_SCRIPTS_DIR environment variables or run this"
echo >&2 "script from the SAGE_ROOT or SAGE_ROOT/local/bin/ directory."
return 1
fi

# Make NEW_SAGE_ROOT absolute
NEW_SAGE_ROOT=`cd "$NEW_SAGE_ROOT" && pwd -P`
if [ -n "$NEW_SAGE_ROOT" ]; then
# Make NEW_SAGE_ROOT absolute
NEW_SAGE_ROOT=`cd "$NEW_SAGE_ROOT" && pwd -P`

# Warn if NEW_SAGE_ROOT does not equal the old SAGE_ROOT
if [ "$SAGE_ROOT" != "$NEW_SAGE_ROOT" -a -n "$SAGE_ROOT" ]; then
echo >&2 "Warning: overwriting SAGE_ROOT environment variable:"
echo >&2 "Old SAGE_ROOT=$SAGE_ROOT"
echo >&2 "New SAGE_ROOT=$NEW_SAGE_ROOT"
# Warn if NEW_SAGE_ROOT does not equal the old SAGE_ROOT
if [ "$SAGE_ROOT" != "$NEW_SAGE_ROOT" -a -n "$SAGE_ROOT" ]; then
echo >&2 "Warning: overwriting SAGE_ROOT environment variable:"
echo >&2 "Old SAGE_ROOT=$SAGE_ROOT"
echo >&2 "New SAGE_ROOT=$NEW_SAGE_ROOT"
fi
fi


Expand Down Expand Up @@ -169,14 +155,15 @@ if [ "$SAGE_ENV_SOURCED" = "$SAGE_ENV_VERSION" ]; then
fi
export SAGE_ENV_SOURCED=$SAGE_ENV_VERSION

export SAGE_ROOT="$NEW_SAGE_ROOT"

if [ -n "$NEW_SAGE_ROOT" ]; then
export SAGE_ROOT="$NEW_SAGE_ROOT"
fi

# sage-env must know where the Sage's script files are.
# Note that SAGE_SCRIPTS_DIR is only used here, so it does not need to
# be exported.
if [ -z "$SAGE_SCRIPTS_DIR" ]; then
if [ -f "$SAGE_ROOT/src/bin/sage-env-config" ]; then
if [ -n "$SAGE_ROOT" -a -f "$SAGE_ROOT/src/bin/sage-env-config" ]; then
# Prefer src/bin/sage-env-config because that's directly
# generated by configure (see Trac #27422)
SAGE_SCRIPTS_DIR="$SAGE_ROOT/src/bin"
Expand All @@ -198,32 +185,36 @@ fi
# 2) compiler installed by sage
# 3) compiler set at configuration time
if [ -z "$CC" ]; then
if [ -x "$SAGE_LOCAL/bin/gcc" ]; then
if [ -n "$SAGE_LOCAL" -a -x "$SAGE_LOCAL/bin/gcc" ]; then
CC=gcc
else
CC="$CONFIGURED_CC"
fi
export CC
fi
if [ -z "$CXX" ]; then
if [ -x "$SAGE_LOCAL/bin/g++" ]; then
if [ -n "$SAGE_LOCAL" -a -x "$SAGE_LOCAL/bin/g++" ]; then
CXX=g++
else
CXX="$CONFIGURED_CXX"
fi
export CXX
fi
if [ -z "$FC" ]; then
if [ -x "$SAGE_LOCAL/bin/gfortran" ]; then
if [ -n "$SAGE_LOCAL" -a -x "$SAGE_LOCAL/bin/gfortran" ]; then
FC=gfortran
else
FC="$CONFIGURED_FC"
fi
export FC
fi
if [ "$UNAME" = "Darwin" ]; then
OBJC="$CONFIGURED_OBJC"
OBJCXX="$CONFIGURED_OBJCXX"
if [ -z "$OBJC" ]; then
OBJC="$CONFIGURED_OBJC"
fi
if [ -z "$OBJCXX" ]; then
OBJCXX="$CONFIGURED_OBJCXX"
fi
export OBJC OBJCXX
fi

Expand Down Expand Up @@ -281,13 +272,21 @@ fi

# Setting Sage-related location environment variables,
# depending on SAGE_ROOT and SAGE_LOCAL which are already defined.
export SAGE_ETC="$SAGE_LOCAL/etc"
export SAGE_SHARE="$SAGE_LOCAL/share"
export SAGE_SPKG_INST="$SAGE_LOCAL/var/lib/sage/installed"
export SAGE_LOGS="$SAGE_ROOT/logs/pkgs"
export SAGE_SRC="$SAGE_ROOT/src"
export SAGE_DOC_SRC="$SAGE_SRC/doc"
export SAGE_DOC="$SAGE_SHARE/doc/sage"
if [ -n "$SAGE_LOCAL" ]; then
export SAGE_ETC="$SAGE_LOCAL/etc"
export SAGE_SHARE="$SAGE_LOCAL/share"
export SAGE_SPKG_INST="$SAGE_LOCAL/var/lib/sage/installed"
fi
if [ -n "$SAGE_SHARE" ]; then
export SAGE_DOC="$SAGE_SHARE/doc/sage"
fi
if [ -n "$SAGE_ROOT" ]; then
export SAGE_LOGS="$SAGE_ROOT/logs/pkgs"
export SAGE_SRC="$SAGE_ROOT/src"
fi
if [ -n "$SAGE_SRC" ]; then
export SAGE_DOC_SRC="$SAGE_SRC/doc"
fi

if [ -n "$SAGE_PKG_CONFIG_PATH" ]; then
# set up external pkg-config to look into SAGE_LOCAL/lib/pkgconfig/
Expand All @@ -299,12 +298,20 @@ if [ -z "${SAGE_ORIG_PATH_SET}" ]; then
SAGE_ORIG_PATH=$PATH && export SAGE_ORIG_PATH
SAGE_ORIG_PATH_SET=True && export SAGE_ORIG_PATH_SET
fi
export PATH="$SAGE_ROOT/build/bin:$SAGE_SRC/bin:$SAGE_LOCAL/bin:$PATH"
if [ -n "$SAGE_LOCAL" ]; then
export PATH="$SAGE_LOCAL/bin:$PATH"
fi
if [ -n "$SAGE_SRC" ]; then
export PATH="$SAGE_SRC/bin:$PATH"
fi
if [ -n "$SAGE_ROOT" ]; then
export PATH="$SAGE_ROOT/build/bin:$PATH"
fi

# We offer a toolchain option, so if $SAGE_LOCAL/toolchain/toolchain-env exists source it.
# Since the user might do something crazy we do not do any checks, but hope for the best.
if [ -f $SAGE_LOCAL/toolchain/toolchain-env ]; then
source $SAGE_LOCAL/toolchain/toolchain-env
if [ -n "$SAGE_LOCAL" -a -f "$SAGE_LOCAL"/toolchain/toolchain-env ]; then
source "$SAGE_LOCAL"/toolchain/toolchain-env
fi

# setting of the variable UNAME (describing the o.s.)
Expand Down Expand Up @@ -338,15 +345,16 @@ if [ "$UNAME" = "Darwin" ]; then
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
fi

# Compile-time path for libraries. This is the equivalent of
# adding the gcc option -L $SAGE_LOCAL/lib.
[ -z "$LIBRARY_PATH" ] || LIBRARY_PATH=":${LIBRARY_PATH}"
export LIBRARY_PATH="$SAGE_LOCAL/lib${LIBRARY_PATH}"

# Compile-time path for include files. This is the equivalent of
# adding the gcc option -I $SAGE_LOCAL/include.
[ -z "$CPATH" ] || CPATH=":${CPATH}"
export CPATH="$SAGE_LOCAL/include${CPATH}"
if [ -n "$SAGE_LOCAL" ]; then
# Compile-time path for libraries. This is the equivalent of
# adding the gcc option -L $SAGE_LOCAL/lib.
[ -z "$LIBRARY_PATH" ] || LIBRARY_PATH=":${LIBRARY_PATH}"
export LIBRARY_PATH="$SAGE_LOCAL/lib${LIBRARY_PATH}"
# Compile-time path for include files. This is the equivalent of
# adding the gcc option -I $SAGE_LOCAL/include.
[ -z "$CPATH" ] || CPATH=":${CPATH}"
export CPATH="$SAGE_LOCAL/include${CPATH}"
fi

SINGULARPATH="$SAGE_LOCAL/share/singular" && export SINGULARPATH
SINGULAR_EXECUTABLE="$SAGE_LOCAL/bin/Singular" && export SINGULAR_EXECUTABLE
Expand All @@ -359,9 +367,12 @@ if [ -z "$SAGE_REPO_AUTHENTICATED" ]; then
SAGE_REPO_AUTHENTICATED="ssh://git@trac.sagemath.org:2222/sage.git"
export SAGE_REPO_AUTHENTICATED
fi
if [ -z "$SAGE_DISTFILES" ]; then
SAGE_DISTFILES="$SAGE_ROOT/upstream"
export SAGE_DISTFILES

if [ -n "$SAGE_ROOT" ]; then
if [ -z "$SAGE_DISTFILES" ]; then
SAGE_DISTFILES="$SAGE_ROOT/upstream"
export SAGE_DISTFILES
fi
fi

# Check that $HOME exists
Expand Down Expand Up @@ -416,11 +427,13 @@ if [ -n "$PYTHONHOME" ]; then
unset PYTHONHOME
fi

LDFLAGS="-L$SAGE_LOCAL/lib -Wl,-rpath,$SAGE_LOCAL/lib $LDFLAGS"
if [ "$UNAME" = "Linux" ]; then
LDFLAGS="-Wl,-rpath-link,$SAGE_LOCAL/lib $LDFLAGS"
if [ -n "$SAGE_LOCAL" ]; then
LDFLAGS="-L$SAGE_LOCAL/lib -Wl,-rpath,$SAGE_LOCAL/lib $LDFLAGS"
if [ "$UNAME" = "Linux" ]; then
LDFLAGS="-Wl,-rpath-link,$SAGE_LOCAL/lib $LDFLAGS"
fi
export LDFLAGS
fi
export LDFLAGS

if [ -z "$IPYTHONDIR" ]; then
# We hardcode a version number in the directory name. The idea is
Expand Down Expand Up @@ -454,7 +467,7 @@ unset R_HOME
unset R_PROFILE
# Do not use the global Makevars.site and ~/.R/Makevars when installing R packages
# Provide empty files to appease some R packages' installation scripts.
if [ -d "$SAGE_LOCAL/lib/R/share" ] ; then
if [ -n "$SAGE_LOCAL" -a -d "$SAGE_LOCAL/lib/R/share" ] ; then
R_MAKEVARS_SITE="$SAGE_LOCAL/lib/R/share/Makevars.site" && export R_MAKEVARS_SITE
if ! [ -f "$R_MAKEVARS_SITE" ] ; then
if ! [ -e "$R_MAKEVARS_SITE" ] ; then
Expand Down Expand Up @@ -485,7 +498,9 @@ fi
export MAXIMA_PREFIX="$SAGE_LOCAL"
export MAXIMA_USERDIR="$DOT_SAGE/maxima"

PERL5LIB="$SAGE_LOCAL/lib/perl5:$PERL5LIB" && export PERL5LIB
if [ -n "$SAGE_LOCAL" ]; then
PERL5LIB="$SAGE_LOCAL/lib/perl5:$PERL5LIB" && export PERL5LIB
fi

# Allow SAGE_BROWSER to override BROWSER (Trac #22449)
if [ -n "$SAGE_BROWSER" ]; then
Expand All @@ -500,10 +515,10 @@ fi
export __sage__=""

# Setup env varariables if ccache is installed
if [ -d "$SAGE_LOCAL/libexec/ccache" ]; then
if [ -n "$SAGE_LOCAL" -a -d "$SAGE_LOCAL/libexec/ccache" ]; then
PATH="$SAGE_LOCAL/libexec/ccache:$PATH"
fi
if [ -z "$CCACHE_BASEDIR" ]; then
if [ -n "$SAGE_ROOT" -a -z "$CCACHE_BASEDIR" ]; then
export CCACHE_BASEDIR="$SAGE_ROOT"
fi

Expand Down Expand Up @@ -580,7 +595,7 @@ if [ "$TOUCH" = "" ]; then
TOUCH="touch" && export TOUCH
fi

if [ "$UNAME" = "CYGWIN" ]; then
if [ "$UNAME" = "CYGWIN" -a -n "$SAGE_LOCAL" ]; then
# Cygwin needs pathnames in PATH to resolve runtime dependencies
PATH="$SAGE_LOCAL/lib/R/lib:$SAGE_LOCAL/lib:$PATH" && export PATH
# And "dlopen" needs them in LD_LIBRARY_PATH, just as on Linuces,
Expand All @@ -590,7 +605,9 @@ if [ "$UNAME" = "CYGWIN" ]; then
fi

# See trac 7186 -- this is needed if ecl is moved
ECLDIR="$SAGE_LOCAL/lib/ecl/" && export ECLDIR
if [ -n "$SAGE_LOCAL" ]; then
ECLDIR="$SAGE_LOCAL/lib/ecl/" && export ECLDIR
fi

# Handle parallel building/testing/...
# See Trac Ticket #12016
Expand Down Expand Up @@ -661,26 +678,28 @@ if [ -r "$SAGE_RC_FILE" ]; then
fi
fi

# If we move the Sage tree then ncurses cannot find terminfo, hence, we
# tell it where to find it. See Trac Ticket #15091

export TERMINFO="$SAGE_LOCAL/share/terminfo"
if [ -n "$SAGE_LOCAL" ]; then
# If we move the Sage tree then ncurses cannot find terminfo, hence, we
# tell it where to find it. See Trac Ticket #15091
export TERMINFO="$SAGE_LOCAL/share/terminfo"

# If nodejs is installed, activate the nodeenv containing it.
# If nodejs is installed, activate the nodeenv containing it.

nodeenv_activate="$SAGE_LOCAL/share/nodejs/activate"
nodeenv_activate="$SAGE_LOCAL/share/nodejs/activate"

if [ -f "$nodeenv_activate" ]; then
# symlinked into nodeenv for specific version of nodejs installed
# The activate script needs to be sourced using its actual path.
nodeenv_activate=`resolvelinks "$nodeenv_activate"`
if [ -f "$nodeenv_activate" ]; then
# symlinked into nodeenv for specific version of nodejs installed
# The activate script needs to be sourced using its actual path.
nodeenv_activate=`resolvelinks "$nodeenv_activate"`

# Don't let nodeenv wipe out the sage-sh/sage-buildsh prompt.
NODE_VIRTUAL_ENV_DISABLE_PROMPT=1 . "$nodeenv_activate"
# Don't let nodeenv wipe out the sage-sh/sage-buildsh prompt.
NODE_VIRTUAL_ENV_DISABLE_PROMPT=1 . "$nodeenv_activate"

if [ $? -ne 0 ]; then
echo >&2 "Warning: failed to activate the nodeenv containing nodejs"
if [ $? -ne 0 ]; then
echo >&2 "Warning: failed to activate the nodeenv containing nodejs"
fi
elif [ -L "$nodeenv_activate" ]; then
echo >&2 "Warning: the nodeenv activation symlink for nodejs is broken"
fi
elif [ -L "$nodeenv_activate" ]; then
echo >&2 "Warning: the nodeenv activation symlink for nodejs is broken"

fi

0 comments on commit 995af9f

Please sign in to comment.