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

Commit

Permalink
Merge branch 'u/mkoeppe/src_bin_sage_env__make_sure__sage_venv_bin_is…
Browse files Browse the repository at this point in the history
…_at_the_beginning_of_the_path' of git://trac.sagemath.org/sage into t/30578/add-src-requirements-txt
  • Loading branch information
Matthias Koeppe committed Nov 14, 2020
2 parents 1a93d0d + 0140f84 commit 948fb49
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ src/*.egg-info/
/src/build
/src/Makefile
/src/bin/sage-env-config
/src/bin/sage-src-env-config

# Virtual environments
src/.env
Expand Down
1 change: 1 addition & 0 deletions build/pkgs/sagelib/src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
'bin/sage-massif',
'bin/sage-omega',
'bin/sage-valgrind',
'bin/sage-venv-config',
'bin/sage-version.sh',
'bin/sage-cleaner',
## Only makes sense in sage-the-distribution. TODO: Move to another installation script.
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ SAGE_SPKG_COLLECT()

dnl AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([build/make/Makefile-auto build/make/Makefile])
AC_CONFIG_FILES([src/bin/sage-env-config build/bin/sage-build-env-config])
AC_CONFIG_FILES([src/bin/sage-env-config src/bin/sage-src-env-config build/bin/sage-build-env-config])

AC_CONFIG_FILES([build/pkgs/sage_conf/src/sage_conf.py build/pkgs/sage_conf/src/setup.cfg])

Expand Down
23 changes: 19 additions & 4 deletions src/bin/sage
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ 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-src-env-config" ]; then
# Not installed script, present only in src/bin/
. "$0-src-env-config" >&2
fi
if [ -x "$0-venv-config" ]; then
# installed by setup.py
export SAGE_VENV=$("$0-venv-config" SAGE_VENV)
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 @@ -196,10 +215,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
3 changes: 3 additions & 0 deletions src/bin/sage-env
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ fi
if [ -n "$SAGE_LOCAL" ]; then
export PATH="$SAGE_LOCAL/bin:$PATH"
fi
if [ -n "$SAGE_VENV" ]; then
export PATH="$SAGE_VENV/bin:$PATH"
fi
if [ -n "$SAGE_SRC" ]; then
export PATH="$SAGE_SRC/bin:$PATH"
fi
Expand Down
39 changes: 39 additions & 0 deletions src/bin/sage-src-env-config.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- shell-script -*- @configure_input@

###########################################################################
#
# Set some environment variables that are needed at the runtime of Sage
# and by its child processes.
#
# This file is only for use when sage is invoked from SAGE_ROOT.
# It is not installed in SAGE_LOCAL.
#
# NOTES:
# - You must *source* this script instead of executing.
# - Use "return" instead of "exit" to signal a failure. Since this
# file is sourced, an "exit" here will actually exit src/bin/sage,
# which is probably not intended.
# - Environment variables that should be available in the Sage environment
# should be exported.
# - This file is only for setting immediate values. Any kind of conditionals
# or computed values are to be set by src/bin/sage-env after sourcing this
# file.
# - Environment variables that are only needed at the time of building
# SPKGs or sagelib should be set in build/bin/sage-build-env-config
# instead.
# - Configuration variables that are only needed by the Sage runtime,
# but not as environment variables, should instead be set in
# build/pkgs/sage_conf/src/sage_conf.py
#
##########################################################################

# SAGE_LOCAL is the installation prefix and can be customized by using
# ./configure --prefix
export SAGE_LOCAL="@prefix@"

# SAGE_VENV is the root of the virtual environment of sagelib.
# Currently, it is identical to SAGE_LOCAL
export SAGE_VENV="@prefix@"

# SAGE_ROOT is the location of the Sage source/build tree.
export SAGE_ROOT="@SAGE_ROOT@"
29 changes: 29 additions & 0 deletions src/bin/sage-venv-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#! /doesnotexist/python3
# this interpreter will be replaced by the interpreter in the venv
# during installation.

try:
from sage_conf import *
except ImportError:
pass

from sys import prefix as SAGE_VENV

def _main():
from argparse import ArgumentParser
from sys import exit, stdout
parser = ArgumentParser()
parser.add_argument('--version', help="show version", action="version",
version='%(prog)s ' + VERSION)
parser.add_argument("VARIABLE", nargs='?', help="output the value of VARIABLE")
args = parser.parse_args()
d = globals()
if args.VARIABLE:
stdout.write('{}\n'.format(d[args.VARIABLE]))
else:
for k, v in d.items():
if not k.startswith('_'):
stdout.write('{}={}\n'.format(k, v))

if __name__ == "__main__":
_main()
1 change: 1 addition & 0 deletions src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
'bin/sage-massif',
'bin/sage-omega',
'bin/sage-valgrind',
'bin/sage-venv-config',
'bin/sage-version.sh',
'bin/sage-cleaner',
## Only makes sense in sage-the-distribution. TODO: Move to another installation script.
Expand Down

0 comments on commit 948fb49

Please sign in to comment.