sagemath/sage

Add conda dev environment

tobiasdiez opened this issue · 77 comments

We add a conda enviroment that is meant for development, i.e. includes tools that one probably needs while working on sage development such as linters, ssh (for contributing to trac) etc.

Moreover, we extract the conda-related things from docs/bootstrap to a new bootstrap-conda script in order to simplify the conda workflow (see updated documentation).

Github workflow run: https://github.com/sagemath/sagetrac-mirror/actions/runs/2268985510

CC: @isuruf @dimpase @saraedum @mkoeppe @slel

Component: build

Author: Tobias Diez

Branch: 87f360c

Reviewer: Matthias Koeppe

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

comment:2

This looks quite odd to me.
Why can't the yml file in the branch be generated from what's already known about Conda packages?

comment:3

I agree, not a good idea to treat this file different from all other of our files that are generated at bootstrap time.

Also jupyter_sphinx should really be added by adding a distros/ file, not ad hoc like this.

comment:4

Replying to @dimpase:

This looks quite odd to me.
Why can't the yml file in the branch be generated from what's already known about Conda packages?

The issue is not so much to generate the file but how it is used. Running bootstrap requires a few dependencies which however are only specified in the environment file. So its a classical chicken-egg problem.

Currently this is resolved by requiring the developers to first create a conda env with the necessary tools for bootstrap, and then later update the env with all dependencies from the env file. With my proposal the overhead occurs only when dependencies are changed (which then requires to commit the changed env file). Overall this should be less work and more convenient.

I agree, not a good idea to treat this file different from all other of our files that are generated at bootstrap time.

The dev environment is special in this respect, since its the only file that you would possibly like to use before the bootstrap.

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

aa144e6Add distros/conda for jupyter_sphinx

Changed commit from 413b081 to aa144e6

comment:6

Replying to @mkoeppe:

Also jupyter_sphinx should really be added by adding a distros/ file, not ad hoc like this.

Done.

comment:7

ok, but please make the initial egg (say, ./bootstrap-conda-dev) minimal - apart from m4 and other autotools, not much else is needed for ./bootstrap.

comment:8

Mhh, having a conda environment just for the bootstrap would also work. But then one still has to run conda create sage-dev -f bootstrap-conda-dev.yml, bootstrap and conda sage-dev update -f environment.yml.

Having one conda environment config containing all necessary tools for bootstrap, compiling and running sage as well as a few additional dev tools is the most convenient, don't you think so?

comment:9

Replying to @dimpase:

ok, but please make the initial egg (say, ./bootstrap-conda-dev) minimal - apart from m4 and other autotools, not much else is needed for ./bootstrap.

+1 on just splitting the generation of the yml files from src/doc/bootstrap (it doesn't really belong there anyway) into a new script. It won't need any of the dependencies that the full bootstrap has.

comment:10

perhaps this should rather become a conda-forge package?

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

2811559Introduce new bootstrap-conda command

Changed commit from aa144e6 to 2811559

comment:12

Replying to @mkoeppe:

Replying to @dimpase:

ok, but please make the initial egg (say, ./bootstrap-conda-dev) minimal - apart from m4 and other autotools, not much else is needed for ./bootstrap.

+1 on just splitting the generation of the yml files from src/doc/bootstrap (it doesn't really belong there anyway) into a new script. It won't need any of the dependencies that the full bootstrap has.

Like this?

comment:13

that's much nicer, but where is the top-level invocation of bootstrap-conda?
Do you mean it's an alternative to ./bootstrap ?

comment:14

I wasn't sure about this one. The procedure now looks as follows:

  • bootstrap-conda
  • conda create
  • bootstrap
  • configure
  • ...

So there is no point in invoking bootstrap-conda during bootstrap.

comment:15

Still need to invoke this so that the generated files end up in the sdist.

comment:16

(See the shell function save in bootstrap)

comment:17

Replying to @tobiasdiez:

I wasn't sure about this one. The procedure now looks as follows:

  • bootstrap-conda
  • conda create
  • bootstrap
  • configure
  • ...

So there is no point in invoking bootstrap-conda during bootstrap.

I thought that ./bootstrap recognises whether we're on conda, or not.
If so, it can invoke bootstrap-conda+conda create.

Otherwise, I'd like to see ./bootstrap getting an optional argument, conda,
to do the calling of bootstrap-conda+conda create and then proceeding.

comment:18

Replying to @dimpase:

I thought that ./bootstrap recognises whether we're on conda, or not.

Not a good idea. The output of bootstrap must not depend on the system configuration. It is packed into the sdist.

comment:19

shouldn't ./bootstrap-conda run on #!/bin/sh, just like ./bootstrap ?

comment:21

Replying to @dimpase:

shouldn't ./bootstrap-conda run on #!/bin/sh, just like ./bootstrap ?

With sh the script is not working, so I took bash as in doc/bootstrap. If that needs to be changed, I need help as its beyond my basic shell script knowledge.

comment:22

Replying to @dimpase:

Otherwise, I'd like to see ./bootstrap getting an optional argument, conda,
to do the calling of bootstrap-conda+conda create and then proceeding.

I like the idea to further simplify the workflow, but lets keep this ticket small and do further streamlining efforts in #33765.

comment:23

Replying to @mkoeppe:

Still need to invoke this so that the generated files end up in the sdist.

Okay, added.

Changed commit from 2811559 to d091d27

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

2a8c1c3Invoke bootstrap-conda during bootstrap
7f51ef0Also delete dev env config file
d091d27Update documentation

Changed commit from d091d27 to 42fc241

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

42fc241Merge branch 'develop' into public/build/conda-dev-env

Description changed:

--- 
+++ 
@@ -1,8 +1,9 @@
 We add a conda enviroment that is meant for development, i.e. includes tools that one probably needs while working on sage development such as linters, ssh (for contributing to trac) etc.
 
-Moreover, we commit the auto-generated file in order to simplify the conda workflow as follows:
+Moreover, we extract the conda-related things from `docs/bootstrap` to a new `bootstrap-conda` script in order to simplify the conda workflow as follows:
 - install mamba/conda
 - git checkout
+- bootstrap-conda
 - mamba create -n sage-dev -f src/environment-dev.yml
 - conda activate sage-dev
 -  ./bootstrap
comment:28

Replying to @tobiasdiez:

Replying to @dimpase:

shouldn't ./bootstrap-conda run on #!/bin/sh, just like ./bootstrap ?

With sh the script is not working, so I took bash as in doc/bootstrap. If that needs to be changed, I need help as its beyond my basic shell script knowledge.

did you try http://manpages.ubuntu.com/manpages/bionic/man1/checkbashisms.1.html ?

comment:29

In this change:

-      $ conda create -n sage-build
+      $ conda env create --file environment.yml
       $ conda activate sage-build

I would suggest to keep the -n so that it's easy to see what needs to be changed if the user wants to use a different name

comment:30

The instructions in "Using conda to provide all dependencies for the Sage library (experimental)" are missing ./bootstrap

comment:31

Also ci-conda.yml should be updated so it tests the updated instructions

comment:32

Replying to @dimpase:

Replying to @tobiasdiez:

Replying to @dimpase:

shouldn't ./bootstrap-conda run on #!/bin/sh, just like ./bootstrap ?

With sh the script is not working, so I took bash as in doc/bootstrap. If that needs to be changed, I need help as its beyond my basic shell script knowledge.

did you try http://manpages.ubuntu.com/manpages/bionic/man1/checkbashisms.1.html ?

It finds things of the form

possible bashism in ./bootstrap-conda line 25 (should be VAR="${VAR}foo"):
                    SYSTEM_PACKAGES+=" $PKG_SYSTEM_PACKAGES"

I would say the += construction is more readable.

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

0716595Add missing bootstrap and combine pip install command
10338a7Change ci as well

Changed commit from 42fc241 to 10338a7

comment:34

Replying to @mkoeppe:

Also ci-conda.yml should be updated so it tests the updated instructions

Good point, done.
https://github.com/sagemath/sagetrac-mirror/actions/runs/2258733820

comment:35

Replying to @mkoeppe:

The instructions in "Using conda to provide all dependencies for the Sage library (experimental)" are missing ./bootstrap

Done.

comment:36

Replying to @tobiasdiez:

Replying to @dimpase:

Replying to @tobiasdiez:

Replying to @dimpase:

shouldn't ./bootstrap-conda run on #!/bin/sh, just like ./bootstrap ?

With sh the script is not working, so I took bash as in doc/bootstrap. If that needs to be changed, I need help as its beyond my basic shell script knowledge.

did you try http://manpages.ubuntu.com/manpages/bionic/man1/checkbashisms.1.html ?

It finds things of the form

possible bashism in ./bootstrap-conda line 25 (should be VAR="${VAR}foo"):
                    SYSTEM_PACKAGES+=" $PKG_SYSTEM_PACKAGES"

I would say the += construction is more readable.

but why do you think that /bin/bash is available everwhere? E.g. on macOS it is probably not the case.

comment:37

I took the bash thing from the original bootstrap script https://github.com/sagemath/sagetrac-mirror/blob/develop/src/doc/bootstrap. But to be honest, I didn't have an idea what I was doing and just mixed different things from the bootstrap scripts until it was working. So I'm totally fine to change it to a more suitable version.

comment:38

git grep '#!.*bash' will show the variant that is in general use

comment:39

Replying to @tobiasdiez:

Replying to @mkoeppe:

Also ci-conda.yml should be updated so it tests the updated instructions

Good point, done.
https://github.com/sagemath/sagetrac-mirror/actions/runs/2258733820

It fails. I don't think the two pip command lines can be combined.

Because of --no-build-isolation, the Sage library (src) cannot advertise its build dependency, so pip cannot possibly know in which order it has to install stuff.

Author: Tobias Diez

Changed commit from 10338a7 to 0cf7334

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

0cf7334Add sage-setup as install-requires dep
comment:43

Absolutely no, this is not an install-requires.

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

6d2b149Use relative paths to not install src package
1dba3baMaybe thats the correct shebang?

Changed commit from 0cf7334 to 1dba3ba

Changed commit from 1dba3ba to c1b2fbf

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

c1b2fbfRevert install_requires change

Changed commit from c1b2fbf to ad56ba3

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

ad56ba3Go back to two pip installs for now
comment:47

Replying to @mkoeppe:

Replying to @tobiasdiez:

Replying to @mkoeppe:

Also ci-conda.yml should be updated so it tests the updated instructions

Good point, done.
https://github.com/sagemath/sagetrac-mirror/actions/runs/2258733820

It fails. I don't think the two pip command lines can be combined.

Because of --no-build-isolation, the Sage library (src) cannot advertise its build dependency, so pip cannot possibly know in which order it has to install stuff.

Build isolation shouldn't be an issue since this only decides if pip tries to create a temporary venv or reuses the existing one for the build env, but not what build dependencies to be installed. Could it be that there is some misconfig of the build dependencies?

Anyway, I've reverted this part and would leave it to a new ticket.

Description changed:

--- 
+++ 
@@ -9,3 +9,5 @@
 -  ./bootstrap
 - ./configure -withsomething
 - pip install --no-build-isolation -v -v --editable pkgs/sage-conf pkgs/sage-setup src
+
+Github workflow run: https://github.com/sagemath/sagetrac-mirror/actions/runs/2268985510
comment:49

Replying to @tobiasdiez:

Build isolation shouldn't be an issue

https://pip.pypa.io/en/stable/cli/pip_install/#cmdoption-no-build-isolation
"Disable isolation when building a modern source distribution. Build dependencies specified by PEP 518 must be already installed if this option is used."

comment:50

comment:29

comment:51

Also, in the edits of the documentation, the information on how to select a Python version have been lost

comment:53

Replying to @mkoeppe:

Replying to @tobiasdiez:

Build isolation shouldn't be an issue

https://pip.pypa.io/en/stable/cli/pip_install/#cmdoption-no-build-isolation
"Disable isolation when building a modern source distribution. Build dependencies specified by PEP 518 must be already installed if this option is used."

Ahh good to know, then I've remembered it wrong. Thanks for the clarification.

comment:54

Replying to @mkoeppe:

In this change:

-      $ conda create -n sage-build
+      $ conda env create --file environment.yml
       $ conda activate sage-build

I would suggest to keep the -n so that it's easy to see what needs to be changed if the user wants to use a different name

Normally the user doesn't need to change the name, and if he does its easy to find on the conda docs how to do this. Thus I don't really see a point in adding an arg that is the same as the default value.

Changed commit from ad56ba3 to b42f5f5

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

b42f5f5Readd how to use specific python version
comment:56

Replying to @mkoeppe:

Also, in the edits of the documentation, the information on how to select a Python version have been lost

Added again.

comment:57

Replying to @tobiasdiez:

Replying to @mkoeppe:

In this change:

-      $ conda create -n sage-build
+      $ conda env create --file environment.yml
       $ conda activate sage-build

I would suggest to keep the -n so that it's easy to see what needs to be changed if the user wants to use a different name

Normally the user doesn't need to change the name

It's as normal as having a second installation in a separate directory

comment:58

Replying to @mkoeppe:

Replying to @tobiasdiez:

Replying to @mkoeppe:

In this change:

-      $ conda create -n sage-build
+      $ conda env create --file environment.yml
       $ conda activate sage-build

I would suggest to keep the -n so that it's easy to see what needs to be changed if the user wants to use a different name

Normally the user doesn't need to change the name

It's as normal as having a second installation in a separate directory

If you want to install two sages in parallel, you should also be able to find the --name arg of conda. But if you insist I can readd the name.

comment:59

Yes please. I added it on purpose in the original version.

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

87f360cReadd name arg

Changed commit from b42f5f5 to 87f360c

comment:61

Replying to @mkoeppe:

Yes please. I added it on purpose in the original version.

okay done

comment:63

conda's pari is not being accepted.

comment:64

This is not specific to this branch and also occurs for develop https://github.com/sagemath/sage/runs/6236167749?check_suite_focus=true
I've opened #33828 for this.

Reviewer: Matthias Koeppe

comment:65

Thanks for checking, I agree. Then it's good to go

comment:66

Thanks!

Description changed:

--- 
+++ 
@@ -1,13 +1,5 @@
 We add a conda enviroment that is meant for development, i.e. includes tools that one probably needs while working on sage development such as linters, ssh (for contributing to trac) etc.
 
-Moreover, we extract the conda-related things from `docs/bootstrap` to a new `bootstrap-conda` script in order to simplify the conda workflow as follows:
-- install mamba/conda
-- git checkout
-- bootstrap-conda
-- mamba create -n sage-dev -f src/environment-dev.yml
-- conda activate sage-dev
--  ./bootstrap
-- ./configure -withsomething
-- pip install --no-build-isolation -v -v --editable pkgs/sage-conf pkgs/sage-setup src
+Moreover, we extract the conda-related things from `docs/bootstrap` to a new `bootstrap-conda` script in order to simplify the conda workflow (see updated documentation).
 
 Github workflow run: https://github.com/sagemath/sagetrac-mirror/actions/runs/2268985510

Changed branch from public/build/conda-dev-env to 87f360c

slel commented
comment:69

The changes in this ticket made ./bootstrap -q less quiet.

Before:

$ ./bootstrap -q

After:

$ ./bootstrap -q
./bootstrap-conda:46: generate conda enviroment files

Follow-up at #34097.

slel commented

Changed commit from 87f360c to none