Opened 4 years ago

Last modified 3 weeks ago

#21707 needs_work task

Meta-ticket: Split sage-env into 5 to clean up sage configuration

Reported by: mkoeppe Owned by:
Priority: major Milestone: sage-9.2
Component: build Keywords:
Cc: embray, jdemeyer, leif, fbissey, dimpase, isuruf, arojas, infinity0, gh-timokau, mjo, jhpalmieri Merged in:
Authors: Matthias Koeppe Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: #29038, #29052 Stopgaps:

Description (last modified by mkoeppe)

src/bin/sage-env (with generated configuration in src/bin/sage-env-config; installed in $SAGE_LOCAL/bin) is used in all of the following contexts:

  1. Sage-the-distribution while building spkgs,
  2. Sage-the-distribution for building sagelib,
  3. for environment variables needed to start Sage,
  4. as variables by Sage at runtime (through sage.env), and
  5. for environment variables affecting subprocesses of Python invoked by sagelib modules.

This ticket proposes to split the configuration according to these 5 contexts. This will make the installation of Sage more modular and flexible.

1./2. Create build/bin/sage-build-env(with generated configuration in build/bin/sage-build-env-config) for the build-time environment variables for sage-the-distribution (spkg and sagelib). It is not installed in $SAGE_LOCAL.

  1. Initially, build/bin/sage-env will call src/bin/sage-env.
  2. In build/make/deps and the scripts generated by build/bin/sage-spkg, source build/bin/sage-build-env in addition to src/bin/sage-env. This is #29052.
  3. Gradually, we will move settings from src/bin/sage-env[-config] to build/bin/sage-build-env[-config] that are known to be only needed for 1./2. (Note that not all compiler-related environment variables can be moved exclusively to 1./2. – some need to be added to 5 as well for some some calls to compilers needed at runtime to support things like %cython (?) and sage.calculus.desolvers.desolve_mintides.) As well as users' use of pip to install additional Python packages!
  4. Eventually, we will remove the call to src/bin/sage-env.

2./3. Obtain sagelib's build-time configuration such as src/setup.py's library_dirs and runtime information (sage.env) from sage-config (introduced in #29038).

  1. In src/Makefile, poison the SAGE_LOCAL variable.
  2. Pass SAGE_PKGS (if still needed at all - see #28815) via sage-config instead of from src/Makefile.

3./4./5. Using sage_conf (Python module and script sage-config, #29038), make sage.all fully functional when imported from a Python, without setting any environment variables (sage-env).

  1. Initially, phase out src/bin/sage-env-config by using sage-config instead.
    • #29384: Clean up src/bin/sage-env-config.in: Move logic to src/bin/sage-env, move non-environment configuration variables to sage_conf.py
  2. Set sage.env variables via the Python module sage_conf instead of relying on information from environment variables. Example: CYSIGNALS_CRASH_DAYS
  3. Set environment variables that are needed only by subprocesses invoked by sagelib in the environment of these subprocesses, rather than relying on them begin set in sage-env. This environment could be provided by a variable sage_conf.SAGE_SUBPROCESS_ENV and/or more invidual variables. Example: R_PROFILE
  4. Finally, remove use of sage-env for all purposes except for sage -sh.

Aspects of downstream sage packaging:

  • The goal is to enable downstream sage packagers to use a whole unmodified src directory to build and install sagelib.
  • Downstream packagers would provide their own "implementation" (one Python module sage_conf.py) of the configuration module defined by #29038, instead of patching sources. They would *not* use the reference implementation in build/pkgs/sage_conf, which is intended for use with sage-the-distribution only.

Relation to the goal of sagelib as a standalone Python library (#21507)

  • An sdist of sagelib, intended to be installed from source from PyPI, could package or depend on another implementation of sage_conf that calls an autoconf-generated configure script (which reuses parts of the build/pkgs/SPKG/spkg-configure.m4 infrastructure); see #29119.

More related tickets:

  • cleaning of src/bin as described in #21569, #21570, #21559.
  • #29133 META-META-TICKET: Build, packaging, testing improvements

Change History (41)

comment:1 Changed 4 years ago by fbissey

One comment. Currently sage_setup is installed because it needs to be installed to be doctested - like the rest of sage. But nothing in sage_setup is really needed at runtime and distro can choose not to install it. I don't in sage-on-gentoo. I tend to push for thing not needed at runtime to be moved in there. And that's where I would have put sage-build-env but I am not going to fight it going into build/bin although I'd like everything used by setup.py to be neatly under src.

comment:2 Changed 4 years ago by mkoeppe

  • Description modified (diff)

Thanks - I've updated the description

comment:3 Changed 4 years ago by mkoeppe

  • Description modified (diff)

comment:4 Changed 4 years ago by embray

I agree.

Consider a slight alternative: Rewrite sage-env as a Python script. This would give it much more flexibility and probably more legibility, including some command-line options for different environments (--build, especially).

The output would of course be the shell commands to actually set the variables. So rather than source sage-env one would eval $(sage-env). My one concern is that it would be slower, but ideally it's something that shouldn't happen frequently anyways, but rather only when not already in sage-env.

comment:5 Changed 4 years ago by fbissey

I have a tendency to mix up sage-env the script and sage.env.py, my comment is really an example of that. However a lot is common between the two.

comment:6 follow-up: Changed 4 years ago by embray

Right--they could be one in the same.

comment:7 in reply to: ↑ 6 Changed 4 years ago by fbissey

Replying to embray:

Right--they could be one in the same.

I have thought about it often. Of course that really means that you'll have to removing all the build time stuff. But in sage-on-gentoo where I ship a very simplified sage-env (in /etc as well) they are virtually doing the same thing, one in shell, the other in python.

comment:8 Changed 4 years ago by embray

In either case--whether making a single script, or two separate shell scripts, this would be useful for gentoo (and probably other distros as well) then right?

comment:9 Changed 4 years ago by fbissey

Probably, the current sage-env is a forest mostly dedicated to the build system. I just discard it and bring my own, it takes less space and maintenance than a mega patch.

comment:10 Changed 4 years ago by mkoeppe

Ideally, the configuration for sagelib runtime should take place in a generated Python file and not involve environment variables at all.

comment:11 Changed 4 years ago by embray

More likely parts of it would be static, and other parts could be generated, but yes, what I meant above in terms of rewriting sage-env in Python was that it would not (by default) involve environment variables at all.

But it's still useful for interacting with other tools, especially for build purposes, as well as dropping into ./sage -sh to be able to set environment variables, which is why I suggest a mode to output a list of variables that can be read from the shell.

comment:12 Changed 12 months ago by mkoeppe

  • Branch set to u/mkoeppe/split_sage_env_into_sage_build_env_and_sage_env

comment:13 Changed 12 months ago by mkoeppe

  • Authors set to Matthias Koeppe
  • Cc dimpase added
  • Commit set to 9189d609fa8cc90d616cb7ea05be405ce196295e
  • Dependencies set to #25130
  • Milestone changed from sage-7.5 to sage-8.8
  • Status changed from new to needs_review

New commits:

7405dd5Move sage-dist-helpers from src/bin to build/bin
9189d60Split out build/bin/sage-build-env-config from sage-env-config

comment:14 Changed 12 months ago by embray

As-is this is going to conflict with tickets like #27825 that are adding still more environment variables needed at build-time to sage-env-config.

I'm completely in favor of this separation in principle though. The question is whether we should do this first and then update tickets like #27825 on top of it, or the other way around?

comment:15 Changed 12 months ago by dimpase

I really would like to first get our existing tickets (#27825, #27822) touching sage-env-config in.

comment:16 Changed 12 months ago by mkoeppe

The tickets would be trivial to rebase on top of this one.

comment:17 follow-up: Changed 12 months ago by mkoeppe

Probably one should introduce a command sage --buildsh, which would provide the larger environment.

comment:18 Changed 11 months ago by embray

For the sake of a bit more terseness I wonder if we could call it just sage-env-build.in and sage-env-build. The only reason for the -config in the other one is to distinguish it from plain sage-env.

Now that I look I'm not even entirely sure we need to separate sage-env-config from sage-env.

I think we could probably have a sage-env.in produce sage-env and get rid of the separate sage-env-config entirely, though it's possible there's some subtlety to that that I'm missing.

comment:19 Changed 11 months ago by embray

  • Branch changed from u/mkoeppe/split_sage_env_into_sage_build_env_and_sage_env to public/split_sage_env_into_sage_build_env_and_sage_env
  • Commit changed from 9189d609fa8cc90d616cb7ea05be405ce196295e to ff0712125a3d05500a1f77e62c371d695d1a9794

Went ahead and rebased on current develop so it could incorporate all the additional variables we've since added.

I didn't change the name of the script yet; I would still prefer to shorten it but if anyone disagrees we can leave it as-is.


New commits:

a34a9f1Move sage-dist-helpers from src/bin to build/bin
ff07121Split out build/bin/sage-build-env-config from sage-env-config

comment:20 Changed 11 months ago by fbissey

The only subtility to sage-env-config in my mind, is that you can touch it or even regenerate it without touching sage-env. But I am sure you don't need a separate file to achieve your objectives in either case.

comment:21 Changed 11 months ago by embray

No, probably not. I might try it, though we'll leave that as a separate exercise from this ticket.

comment:22 Changed 11 months ago by embray

  • Milestone changed from sage-8.8 to sage-8.9

Moving tickets from the Sage 8.8 milestone that have been actively worked on in the last six months to the next release milestone (optimistically).

comment:23 Changed 5 months ago by embray

  • Milestone changed from sage-8.9 to sage-9.1

Ticket retargeted after milestone closed

comment:24 Changed 4 months ago by mkoeppe

  • Status changed from needs_review to needs_work

comment:25 follow-up: Changed 4 months ago by mkoeppe

The run-time environment variables of sage could as well be configured by a Python module src/sage/env_config.py - see #29022.

comment:26 in reply to: ↑ 17 Changed 4 months ago by mkoeppe

Replying to mkoeppe:

Probably one should introduce a command sage --buildsh, which would provide the larger environment.

As an extension of this, there could be sage --buildsh SPKG, which would set up the environment in which spkg-install runs. This could be useful for testing new versions of packages.

comment:27 in reply to: ↑ 25 Changed 4 months ago by mkoeppe

Replying to mkoeppe:

The run-time environment variables of sage could as well be configured by a Python module src/sage/env_config.py - see #29022.

Or #29038 - Python package sage_conf: Provides optional configuration information for sagelib

comment:28 Changed 4 months ago by mkoeppe

  • Branch public/split_sage_env_into_sage_build_env_and_sage_env deleted
  • Cc isuruf arojas infinity0 gh-timokau added
  • Commit ff0712125a3d05500a1f77e62c371d695d1a9794 deleted
  • Dependencies changed from #25130 to #29038
  • Description modified (diff)
  • Status changed from needs_work to needs_info
  • Summary changed from Split sage-env into sage-build-env and sage-env to Split sage-env into 5
  • Type changed from enhancement to task

Hoping for input from people involved in packaging.

comment:29 Changed 4 months ago by mkoeppe

  • Status changed from needs_info to needs_review

comment:30 Changed 4 months ago by mkoeppe

  • Description modified (diff)

comment:31 Changed 4 months ago by mkoeppe

  • Description modified (diff)

comment:32 Changed 4 months ago by mkoeppe

  • Dependencies changed from #29038 to #29038, #29052

comment:33 Changed 4 months ago by mkoeppe

  • Summary changed from Split sage-env into 5 to Meta-ticket: Split sage-env into 5 to clean up sage configuration

comment:34 Changed 4 months ago by mkoeppe

  • Description modified (diff)

comment:35 Changed 4 months ago by mkoeppe

  • Description modified (diff)

comment:36 Changed 4 months ago by mkoeppe

  • Cc mjo added

comment:37 Changed 2 months ago by mkoeppe

  • Description modified (diff)
  • Status changed from needs_review to needs_work

comment:38 Changed 6 weeks ago by mkoeppe

  • Description modified (diff)

comment:39 Changed 5 weeks ago by mkoeppe

  • Milestone changed from sage-9.1 to sage-9.2

comment:40 Changed 3 weeks ago by mkoeppe

  • Description modified (diff)

comment:41 Changed 3 weeks ago by mkoeppe

  • Cc jhpalmieri added
Note: See TracTickets for help on using tickets.