Opened 2 years ago
Last modified 8 weeks ago
#25486 needs_review enhancement
Discover SAGE_SCRIPTS_DIR to make $SAGE_LOCAL/bin/sage work from any directory, in an environment without SAGE_* variables
Reported by:  mkoeppe  Owned by:  

Priority:  major  Milestone:  sage9.2 
Component:  build  Keywords:  SAGE_LOCAL, SAGE_ROOT 
Cc:  jdemeyer, nbruin, embray, fbissey, charpent, thansen, saraedum, slelievre, ghtimokau, dimpase  Merged in:  
Authors:  Matthias Koeppe  Reviewers:  
Report Upstream:  N/A  Work issues:  
Branch:  u/mkoeppe/_sage_local_bin_sage_should_work_in_an_environment_without_sage___variables (Commits)  Commit:  3671eb340e39a730c4595f9c81b06a09313ad335 
Dependencies:  Stopgaps: 
Description (last modified by )
This ticket makes $SAGE_LOCAL/bin/sage
work without environment variables set, or the current working directory to be something particular.
It does that by
 adding
SAGE_ROOT
to$SAGE_LOCAL/bin/sageenvconfig
(viasrc/bin/sageenvconfig.in
).  adding code to the top of
sageenv
that determinesSAGE_SCRIPTS_DIR
from the directory of itself.
Previous discussion in https://groups.google.com/d/msg/sagedevel/oODph9yjaI/FVeBsCk_CgAJ:
On Wednesday, May 30, 2018 at 9:01:59 AM UTC7, Nils Bruin wrote:
Currently, if I run the script $SAGE_LOCAL/bin/sage in my normal environment (where SAGE_ROOT is not set) then I get:
Error: You must set the SAGE_ROOT environment variable or run this script from the SAGE_ROOT or SAGE_ROOT/local/bin/ directory. Error setting environment variables by sourcing '/usr/local/sage/sagegit/local/bin/sageenv'; possibly contact sagedevel (see http://groups.google.com/group/sagedevel).
If instead I run the script $SAGE_ROOT/sage a value for SAGE_ROOT is figured out and everything works fine when called from my normal environment.
Change History (25)
comment:1 Changed 2 years ago by
 Cc slelievre added
 Keywords SAGE_LOCAL SAGE_ROOT added
comment:2 Changed 2 years ago by
One comment: the new version of GAP deprecates the gap.sh as the right way to start GAP. (The gap binary detects the directory that it lives in, and uses that as the default library directory.) Relying on the shell script to check for SAGE_LOCAL probably isn't a great idea for GAP 4.9.1 or later. That might make this more pressing.
If you do need to check for the SAGE_LOCAL variable, it seems to me like a better place to check would be in GAP code. (The IO_environ()
function from the IO package will read the environment, which you could do on package load.) But I'm coming from outside, and might not be aware of all issues.
Also, I'm the Gap.app author. If it still looks necessary when I next make updates, I'll consider adding logic to set SAGE_LOCAL to a sensible guess on startup. I ran out of time for this release (as I wanted to get something out at the same time as GAP 4.9.1). I'd love for it to no longer be necessary!
comment:3 Changed 2 years ago by
I don't think there should be anything in GAP that cares about $SAGE_LOCAL
. If anything Sage's bin/gap
should just be a wrapper script that sets the necessary environment variables, rather than patching gap.sh
which it currently does =_=
comment:4 Changed 2 years ago by
 Cc ghtimokau added
comment:5 Changed 5 months ago by
A step into this direction: #29022 "Create module src/sage/env_config.py
from src/sage/env_config.py.in
, defining variables for use in sage.env
.
comment:6 Changed 5 months ago by
 Dependencies set to #29022
comment:7 Changed 5 months ago by
 Milestone changed from sage8.3 to sage9.1
comment:8 Changed 5 months ago by
 Branch set to u/mkoeppe/_sage_local_bin_sage_should_work_in_an_environment_without_sage___variables
comment:9 Changed 5 months ago by
 Cc dimpase added
 Commit set to c7b109099922ef6cdcceb6e4510cdeb096a94661
 Description modified (diff)
 Status changed from new to needs_review
This is adapted from an old branch of #21479 (./configure prefix=SAGE_LOCAL
), when $SAGE_LOCAL/bin/sageenvconfig
was introduced; but then a less ambitious solution was implemented for that ticket.
New commits:
a53e0df  src/bin/sageenvconfig.in: Define SAGE_ROOT

c7b1090  src/bin/sageenv: Obtain SAGE_SCRIPTS_DIR from sageenv invocation

comment:10 Changed 5 months ago by
 Dependencies #29022 deleted
 Description modified (diff)
Removed a dependency that is not needed.
comment:11 Changed 5 months ago by
 Summary changed from $SAGE_LOCAL/bin/sage should work in an environment without SAGE_* variables to Discover SAGE_SCRIPTS_DIR to make $SAGE_LOCAL/bin/sage work from any directory, in an environment without SAGE_* variables
comment:12 followups: ↓ 15 ↓ 16 Changed 5 months ago by
 Status changed from needs_review to needs_work
A few suggestions:
rename SOURCED_SAGE_ENV_CONFIG
to SAGE_ENV_CONFIG_SOURCED
(we already have a SAGE_ENV_SOURCED
) variable as well.
Make sageenvconfig
itself responsible for setting SAGE_ENV_CONFIG_SOURCED
, rather than setting it in sageenv
.
+# SAGE_ROOT is the location of the Sage source/build tree. +export SAGE_ROOT="@abs_top_srcdir@"
Wouldn't this permanently encode the directory in which Sage happens to be built in any Sage installation, including for binary builds? E.g. if Volker does a binary build and publishes it, then it will contain in local/bin/sageenvconfig
something like SAGE_ROOT=/home/vbraun/src/sage/
and won't work when moved. So I'm not sure this make sense to me...
How do distros currently handle $SAGE_ROOT
, a path that doesn't have significant meaning in standard installs? Perhaps what we need is to do away with any dependency on $SAGE_ROOT
at runtime.
comment:13 Changed 5 months ago by
I think otherwise in principle I'm +1 to this but I don't see how it resolves that last question...
comment:14 Changed 5 months ago by
 Commit changed from c7b109099922ef6cdcceb6e4510cdeb096a94661 to 37c68fb9361c2a4c488ed8a8e1450d36af364eed
Branch pushed to git repo; I updated commit sha1. New commits:
37c68fb  Rename SOURCED_SAGE_ENV_CONFIG > SAGE_ENV_CONFIG_SOURCED, set it in src/bin/sageenvconfig.in

comment:15 in reply to: ↑ 12 Changed 5 months ago by
Replying to embray:
A few suggestions:
rename
SOURCED_SAGE_ENV_CONFIG
toSAGE_ENV_CONFIG_SOURCED
(we already have aSAGE_ENV_SOURCED
) variable as well.Make
sageenvconfig
itself responsible for settingSAGE_ENV_CONFIG_SOURCED
, rather than setting it insageenv
.
Thanks! Done.
comment:16 in reply to: ↑ 12 Changed 5 months ago by
Replying to embray:
+# SAGE_ROOT is the location of the Sage source/build tree. +export SAGE_ROOT="@abs_top_srcdir@"Wouldn't this permanently encode the directory in which Sage happens to be built in any Sage installation,
Yes, that's what it does. Sage installations (SAGE_LOCAL
) and nondistclean
source trees (SAGE_ROOT
) are not relocatable with or without this ticket.
including for binary builds? E.g. if Volker does a binary build and publishes it, then it will contain in
local/bin/sageenvconfig
something likeSAGE_ROOT=/home/vbraun/src/sage/
and won't work when moved.
The binary build uses SAGE_ROOT
= a long pseudorandom path and then rewrites all paths, including this one, using https://github.com/sagemath/binarypkg/blob/master/binary_pkg/templates/relocateonce.py the first time that SAGE_ROOT/sage
is used.
How do distros currently handle
$SAGE_ROOT
, a path that doesn't have significant meaning in standard installs?
Distributions tend to replace all of sageenv
by their own tooling anyway.
Perhaps what we need is to do away with any dependency on
$SAGE_ROOT
at runtime.
Yes, in fact, there's very little left (see #25828/#28815). In any case, that's orthogonal to the present ticket.
comment:17 Changed 5 months ago by
 Status changed from needs_work to needs_review
comment:18 Changed 4 months ago by
 Commit changed from 37c68fb9361c2a4c488ed8a8e1450d36af364eed to 6382db9647f59d550026ea0ea63cf4f2eb13a453
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
4184f49  src/bin/sageenvconfig.in: Define SAGE_ROOT

8cbeafa  src/bin/sageenv: Obtain SAGE_SCRIPTS_DIR from sageenv invocation

6382db9  Rename SOURCED_SAGE_ENV_CONFIG > SAGE_ENV_CONFIG_SOURCED, set it in src/bin/sageenvconfig.in

comment:19 Changed 4 months ago by
Rebased on 9.1.beta2, needs review
comment:20 Changed 4 months ago by
 Commit changed from 6382db9647f59d550026ea0ea63cf4f2eb13a453 to b6c35a715bd2d496a3aea8982f80b470e68aa98d
Branch pushed to git repo; I updated commit sha1. New commits:
b6c35a7  Merge tag '9.1.beta4' into t/25486/_sage_local_bin_sage_should_work_in_an_environment_without_sage___variables

comment:21 Changed 3 months ago by
 Commit changed from b6c35a715bd2d496a3aea8982f80b470e68aa98d to b4277ec6fdc0250ffc81360837d1b82d09b1aa5b
Branch pushed to git repo; I updated commit sha1. New commits:
b4277ec  Merge tag '9.1.beta6' into t/25486/_sage_local_bin_sage_should_work_in_an_environment_without_sage___variables

comment:22 Changed 3 months ago by
 Commit changed from b4277ec6fdc0250ffc81360837d1b82d09b1aa5b to c6879b51afa4235733fdbb713613995a4fe23afc
Branch pushed to git repo; I updated commit sha1. New commits:
c6879b5  Merge tag '9.1.beta7' into t/25486/_sage_local_bin_sage_should_work_in_an_environment_without_sage___variables

comment:23 Changed 3 months ago by
 Commit changed from c6879b51afa4235733fdbb713613995a4fe23afc to 3671eb340e39a730c4595f9c81b06a09313ad335
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
afd05b3  src/bin/sageenvconfig.in: Define SAGE_ROOT

50d2e09  src/bin/sageenv: Obtain SAGE_SCRIPTS_DIR from sageenv invocation

3671eb3  Rename SOURCED_SAGE_ENV_CONFIG > SAGE_ENV_CONFIG_SOURCED, set it in src/bin/sageenvconfig.in

comment:24 Changed 3 months ago by
Rebased on 9.1.beta8, needs review
comment:25 Changed 8 weeks ago by
 Milestone changed from sage9.1 to sage9.2
pushing these forward to 9.2
Likewise, a naive trial to start the GAP shipped by Sage fails:
and one instead has to run:
or
(where
/path/to/sagedir
should be replaced by the actual path to the Sage installation directory).This makes it hard to use Gap.app, the macOS interface to GAP by Russ Woodroofe, with the GAP shipped by Sage.