Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discover SAGE_SCRIPTS_DIR to make $SAGE_LOCAL/bin/sage work from any directory, in an environment without SAGE_* variables #25486

Closed
mkoeppe opened this issue May 31, 2018 · 48 comments

Comments

@mkoeppe
Copy link
Contributor

mkoeppe commented May 31, 2018

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/sage-env-config (via src/bin/sage-env-config.in).
  • adding code to the top of sage-env that determines SAGE_SCRIPTS_DIR from the directory of itself.

Previous discussion in https://groups.google.com/d/msg/sage-devel/oODph9-yjaI/FVeBsCk_CgAJ:

On Wednesday, May 30, 2018 at 9:01:59 AM UTC-7, 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/sage-git/local/bin/sage-env';
possibly contact sage-devel (see http://groups.google.com/group/sage-devel).

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.

CC: @jdemeyer @nbruin @embray @kiwifb @EmmanuelCharpentier @tobihan @saraedum @slel @timokau @dimpase

Component: build

Keywords: SAGE_LOCAL, SAGE_ROOT

Author: Matthias Koeppe

Branch: 4415da5

Reviewer: Dima Pasechnik

Issue created by migration from https://trac.sagemath.org/ticket/25486

@mkoeppe mkoeppe added this to the sage-8.3 milestone May 31, 2018
@slel
Copy link
Member

slel commented Jun 1, 2018

comment:1

Likewise, a naive trial to start the GAP shipped by Sage fails:

$ /path/to/sagedir/local/bin/gap
Set the environment variable SAGE_LOCAL.

and one instead has to run:

$ /path/to/sagedir/sage --gap

or

$ SAGE_LOCAL='/path/to/sagedir' /path/to/sagedir/local/bin/gap

(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.

@slel
Copy link
Member

slel commented Jun 1, 2018

Changed keywords from none to SAGE_LOCAL, SAGE_ROOT

@RussWoodroofe
Copy link

comment:2

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!

@embray
Copy link
Contributor

embray commented Jul 10, 2018

comment:3

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 =_=

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 15, 2020

comment:5

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.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 15, 2020

Dependencies: #29022

@mkoeppe mkoeppe modified the milestones: sage-8.3, sage-9.1 Jan 15, 2020
@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 17, 2020

@mkoeppe

This comment has been minimized.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 17, 2020

comment:9

This is adapted from an old branch of #21479 (./configure --prefix=SAGE_LOCAL), when $SAGE_LOCAL/bin/sage-env-config was introduced; but then a less ambitious solution was implemented for that ticket.


New commits:

a53e0dfsrc/bin/sage-env-config.in: Define SAGE_ROOT
c7b1090src/bin/sage-env: Obtain SAGE_SCRIPTS_DIR from sage-env invocation

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 17, 2020

Author: Matthias Koeppe

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 17, 2020

Commit: c7b1090

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 18, 2020

comment:10

Removed a dependency that is not needed.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 18, 2020

Changed dependencies from #29022 to none

@mkoeppe

This comment has been minimized.

@mkoeppe mkoeppe changed the title $SAGE_LOCAL/bin/sage should work in an environment without SAGE_* variables Discover SAGE_SCRIPTS_DIR to make $SAGE_LOCAL/bin/sage work from any directory, in an environment without SAGE_* variables Jan 18, 2020
@embray
Copy link
Contributor

embray commented Jan 22, 2020

comment:12

A few suggestions:

rename SOURCED_SAGE_ENV_CONFIG to SAGE_ENV_CONFIG_SOURCED (we already have a SAGE_ENV_SOURCED) variable as well.

Make sage-env-config itself responsible for setting SAGE_ENV_CONFIG_SOURCED, rather than setting it in sage-env.

+# 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/sage-env-config 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.

@embray
Copy link
Contributor

embray commented Jan 22, 2020

comment:13

I think otherwise in principle I'm +1 to this but I don't see how it resolves that last question...

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 22, 2020

Branch pushed to git repo; I updated commit sha1. New commits:

37c68fbRename SOURCED_SAGE_ENV_CONFIG -> SAGE_ENV_CONFIG_SOURCED, set it in src/bin/sage-env-config.in

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 22, 2020

Changed commit from c7b1090 to 37c68fb

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 22, 2020

comment:15

Replying to @embray:

A few suggestions:

rename SOURCED_SAGE_ENV_CONFIG to SAGE_ENV_CONFIG_SOURCED (we already have a SAGE_ENV_SOURCED) variable as well.

Make sage-env-config itself responsible for setting SAGE_ENV_CONFIG_SOURCED, rather than setting it in sage-env.

Thanks! Done.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jan 22, 2020

comment:16

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 non-distclean 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/sage-env-config something like SAGE_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/binary-pkg/blob/master/binary_pkg/templates/relocate-once.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 sage-env 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.

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Apr 14, 2020

comment:25

pushing these forward to 9.2

@mkoeppe mkoeppe modified the milestones: sage-9.1, sage-9.2 Apr 14, 2020
@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 7, 2020

Changed commit from 3671eb3 to 4415da5

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jun 7, 2020

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

37d79acsrc/bin/sage-env-config.in: Define SAGE_ROOT
68c1762src/bin/sage-env: Obtain SAGE_SCRIPTS_DIR from sage-env invocation
4415da5Rename SOURCED_SAGE_ENV_CONFIG -> SAGE_ENV_CONFIG_SOURCED, set it in src/bin/sage-env-config.in

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jun 7, 2020

comment:27

Rebased on 9.2.beta0

@dimpase
Copy link
Member

dimpase commented Jun 11, 2020

comment:28

lgtm

@dimpase
Copy link
Member

dimpase commented Jun 11, 2020

Reviewer: Dima Pasechnik

@dimpase
Copy link
Member

dimpase commented Jun 11, 2020

comment:29

oops, sorry, doesn't it need a shebang to make sure it is running in bash?

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jun 12, 2020

comment:30

Well, I guess this ticket conflicts somehow with #29345

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jun 24, 2020

comment:31

Actually it is already documented that sage-env "uses bash features, so it cannot be used with other shells." It is sourced by other scripts, so it does not need a #! line.

@dimpase
Copy link
Member

dimpase commented Jun 25, 2020

comment:32

lgtm

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jun 26, 2020

comment:33

Thanks!

@vbraun
Copy link
Member

vbraun commented Jun 27, 2020

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 5, 2020

comment:35

Follow up: #29446

@mkoeppe
Copy link
Contributor Author

mkoeppe commented Jul 5, 2020

Changed commit from 4415da5 to none

@orlitzky
Copy link
Contributor

comment:36

Replying to @mkoeppe:

Actually it is already documented that sage-env "uses bash features, so it cannot be used with other shells." It is sourced by other scripts, so it does not need a #! line.

I fixed all of the bashisms in #29345, but missed that comment. The sage build now fails again with any other /bin/sh:

cd '/home/mjo/src/sage.git/build/pkgs/sage_conf' && . '/home/mjo/src/sage.git/src/bin/sage-env' && . '/home/mjo/src/sage.git/build/bin/sage-build-env-config' && sage-logger -p '/home/mjo/src/sage.git/build/pkgs/sage_conf/spkg-install' '/home/mjo/src/sage.git/logs/pkgs/sage_conf-none.log'
/bin/sh: 123: /home/mjo/src/sage.git/src/bin/sage-env: Bad substitution
Error: SAGE_SCRIPTS_DIR is set to a bad value:
SAGE_SCRIPTS_DIR=/home/mjo/src/sage.git/build/pkgs/sage_conf
You must correct it or erase it and rerun this script
make[3]: *** [Makefile:2022: /home/mjo/src/sage.git/local/var/lib/sage/installed/sage_conf-none] Error 1

Debian's dash shell is crippled, but would it be possible to symlink /bin/sh to dash on e.g. Arch linux, or maybe to ksh on some other distro that we have CI for? (To prevent regressions in the future?)

@orlitzky
Copy link
Contributor

comment:37

Follow-up on #30128

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants