Skip to content

Commit 6f44770

Browse files
author
Release Manager
committed
gh-36405: `bootstrap-conda`: Refactor, generate versioned environment files <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> - Environment files are now versioned with the Python minor version, as proposed in (and cherry-picked from) #35986 by @tobiasdiez - CI for conda now uses `--enable-system-site-packages` from #36141 by @orlitzky Split out from <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #36405 Reported by: Matthias Köppe Reviewer(s): Tobias Diez
2 parents e716501 + 73ab316 commit 6f44770

File tree

10 files changed

+166
-105
lines changed

10 files changed

+166
-105
lines changed

.devcontainer/onCreate-conda.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -e
44
# Create conda environment
55
./bootstrap-conda
66
conda install mamba -n base -c conda-forge -y
7-
mamba env create --file src/environment-dev.yml || mamba env update --file src/environment-dev.yml
7+
mamba env create --file src/environment-dev-3.11.yml || mamba env update --file src/environment-dev-3.11.yml
88
conda init bash
99

1010
# Build sage

.github/workflows/ci-conda.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
with:
6060
path: ~/conda_pkgs_dir
6161
key:
62-
${{ runner.os }}-conda-${{ hashFiles('src/environment.yml') }}
62+
${{ runner.os }}-conda-${{ hashFiles('src/environment-3.11.yml') }}
6363

6464
- name: Setup Conda
6565
uses: conda-incubator/setup-miniconda@v2
@@ -68,8 +68,8 @@ jobs:
6868
mamba-version: "*"
6969
channels: conda-forge,defaults
7070
channel-priority: true
71-
activate-environment: sage-build
72-
environment-file: src/${{ matrix.conda-env }}.yml
71+
activate-environment: sage
72+
environment-file: src/${{ matrix.conda-env }}-${{ matrix.python }}.yml
7373

7474
- name: Print Conda environment
7575
shell: bash -l {0}
@@ -83,7 +83,7 @@ jobs:
8383
run: |
8484
./bootstrap
8585
echo "::add-matcher::.github/workflows/configure-systempackage-problem-matcher.json"
86-
./configure --enable-build-as-root --with-python=$CONDA_PREFIX/bin/python --prefix=$CONDA_PREFIX $(for pkg in $(./sage -package list :standard: --has-file spkg-configure.m4 --has-file distros/conda.txt --exclude rpy2); do echo --with-system-$pkg=force; done)
86+
./configure --enable-build-as-root --with-python=$CONDA_PREFIX/bin/python --prefix=$CONDA_PREFIX --enable-system-site-packages $(for pkg in $(./sage -package list :standard: --has-file spkg-configure.m4 --has-file distros/conda.txt --exclude rpy2); do echo --with-system-$pkg=force; done)
8787
echo "::remove-matcher owner=configure-system-package-warning::"
8888
echo "::remove-matcher owner=configure-system-package-error::"
8989

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,29 @@
2727
# no longer generated, but may still be in user worktrees
2828
/src/lib/pkgconfig
2929

30+
# Environment files generated by bootstrap-conda.
31+
# The files without Python version are no longer generated
32+
# but may still be in users' directories.
3033
/environment.yml
34+
/environment-3.9.yml
35+
/environment-3.10.yml
36+
/environment-3.11.yml
3137
/environment-optional.yml
38+
/environment-optional-3.9.yml
39+
/environment-optional-3.10.yml
40+
/environment-optional-3.11.yml
3241
/src/environment.yml
42+
/src/environment-3.9.yml
43+
/src/environment-3.10.yml
44+
/src/environment-3.11.yml
3345
/src/environment-dev.yml
46+
/src/environment-dev-3.9.yml
47+
/src/environment-dev-3.10.yml
48+
/src/environment-dev-3.11.yml
3449
/src/environment-optional.yml
50+
/src/environment-optional-3.9.yml
51+
/src/environment-optional-3.10.yml
52+
/src/environment-optional-3.11.yml
3553

3654
/src/setup.cfg
3755
/src/requirements.txt

.gitpod.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ tasks:
88
# Create conda environment, then configure and build sage
99
init: >-
1010
./bootstrap-conda
11-
&& mamba env create --file src/environment-dev.yml --prefix venv
11+
&& mamba env create --file src/environment-dev-3.11.yml --prefix venv
1212
&& conda config --append envs_dirs $(pwd)
1313
&& conda activate $(pwd)/venv
1414
&& ./bootstrap

Makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,7 @@ bootstrap-clean:
158158
rm -rf config/install-sh config/compile config/config.guess config/config.sub config/missing configure build/make/Makefile-auto.in
159159
rm -f src/doc/en/installation/*.txt
160160
rm -rf src/doc/en/reference/spkg/*.rst
161-
rm -f environment.yml
162-
rm -f src/environment.yml
163-
rm -f src/environment-dev.yml
164-
rm -f environment-optional.yml
165-
rm -f src/environment-optional.yml
161+
for a in environment environment-optional src/environment src/environment-dev src/environment-optional; do rm -f $$a.yml $$a-3.[89].yml $$a-3.1[0-9].yml; done
166162
rm -f src/Pipfile
167163
rm -f src/pyproject.toml
168164
rm -f src/requirements.txt

bootstrap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,10 @@ save () {
226226
build/make/Makefile-auto.in \
227227
src/doc/en/installation/*.txt \
228228
src/doc/en/reference/spkg/*.rst \
229-
environment.yml \
230-
src/environment.yml \
231-
environment-optional.yml \
232-
src/environment-optional.yml \
229+
environment-3.[89].yml environment-3.1[0-9].yml \
230+
src/environment-3.[89].yml src/environment-3.1[0-9].yml \
231+
environment-optional-3.[89].yml environment-optional-3.1[0-9].yml \
232+
src/environment-optional-3.[89].yml src/environment-optional-3.1[0-9].yml \
233233
src/Pipfile \
234234
src/pyproject.toml \
235235
src/requirements.txt \

bootstrap-conda

Lines changed: 116 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -11,112 +11,151 @@ STRIP_COMMENTS="sed s/#.*//;"
1111
shopt -s extglob
1212

1313
DEVELOP_SPKG_PATTERN="@(_develop$(for a in $(head -n 1 build/pkgs/_develop/dependencies); do echo -n "|"$a; done))"
14-
BOOTSTRAP_PACKAGES=$(echo $(${STRIP_COMMENTS} build/pkgs/_bootstrap/distros/conda.txt))
15-
SYSTEM_PACKAGES=
16-
OPTIONAL_SYSTEM_PACKAGES=
17-
SAGELIB_SYSTEM_PACKAGES=
18-
SAGELIB_OPTIONAL_SYSTEM_PACKAGES=
19-
DEVELOP_SYSTEM_PACKAGES=
14+
BOOTSTRAP_PACKAGES=_bootstrap
15+
PACKAGES=
16+
OPTIONAL_PACKAGES=
17+
SAGELIB_PACKAGES=
18+
SAGELIB_OPTIONAL_PACKAGES=
19+
DEVELOP_PACKAGES=
20+
2021
for PKG_BASE in $(sage-package list --has-file distros/conda.txt --exclude _sagemath); do
2122
PKG_SCRIPTS=build/pkgs/$PKG_BASE
2223
SYSTEM_PACKAGES_FILE=$PKG_SCRIPTS/distros/conda.txt
2324
PKG_TYPE=$(cat $PKG_SCRIPTS/type)
2425
PKG_SYSTEM_PACKAGES=$(echo $(${STRIP_COMMENTS} $SYSTEM_PACKAGES_FILE))
25-
if [ -n "PKG_SYSTEM_PACKAGES" ]; then
26+
if [ -n "$PKG_SYSTEM_PACKAGES" ]; then
2627
if [ -f $PKG_SCRIPTS/spkg-configure.m4 ]; then
28+
if grep -q SAGE_PYTHON_PACKAGE_CHECK $PKG_SCRIPTS/spkg-configure.m4; then
29+
# Python package that would need --enable-system-site-packages to be used
30+
# with the Sage distribution, but we do not recommend that for conda.
31+
PKG_SAGELIB_ONLY=yes
32+
else
33+
PKG_SAGELIB_ONLY=no
34+
fi
35+
else
36+
# No spkg-configure, so the Sage distribution is not able to make use of this package.
37+
PKG_SAGELIB_ONLY=yes
38+
fi
39+
[ -n "$BOOTSTRAP_VERBOSE" ] && echo "$PKG_BASE:$PKG_TYPE:$PKG_SAGELIB_ONLY"
40+
if [ $PKG_SAGELIB_ONLY = no ]; then
2741
case "$PKG_BASE:$PKG_TYPE" in
2842
*:standard)
29-
SYSTEM_PACKAGES+=" $PKG_SYSTEM_PACKAGES"
43+
PACKAGES+=" $PKG_BASE"
3044
;;
3145
$DEVELOP_SPKG_PATTERN:*)
32-
DEVELOP_SYSTEM_PACKAGES+=" $PKG_SYSTEM_PACKAGES"
46+
DEVELOP_PACKAGES+=" $PKG_BASE"
3347
;;
3448
*)
35-
OPTIONAL_SYSTEM_PACKAGES+=" $PKG_SYSTEM_PACKAGES"
49+
OPTIONAL_PACKAGES+=" $PKG_BASE"
3650
;;
3751
esac
3852
else
3953
case "$PKG_BASE:$PKG_TYPE" in
4054
*:standard)
41-
SAGELIB_SYSTEM_PACKAGES+=" $PKG_SYSTEM_PACKAGES"
55+
SAGELIB_PACKAGES+=" $PKG_BASE"
4256
;;
4357
$DEVELOP_SPKG_PATTERN:*)
44-
DEVELOP_SYSTEM_PACKAGES+=" $PKG_SYSTEM_PACKAGES"
58+
DEVELOP_PACKAGES+=" $PKG_BASE"
4559
;;
4660
*)
47-
SAGELIB_OPTIONAL_SYSTEM_PACKAGES+=" $PKG_SYSTEM_PACKAGES"
61+
SAGELIB_OPTIONAL_PACKAGES+=" $PKG_BASE"
4862
;;
4963
esac
5064
fi
5165
fi
5266
done
67+
unset PKG_SYSTEM_PACKAGES
68+
69+
[ -n "$BOOTSTRAP_VERBOSE" ] && echo "## Collected:" && set | grep PACKAGES=
70+
71+
# Translate to system packages
72+
export ENABLE_SYSTEM_SITE_PACKAGES=yes # Disable filtering in sage-get-system-packages
73+
SYSTEM_PACKAGES=$(sage-get-system-packages conda $PACKAGES)
74+
BOOTSTRAP_SYSTEM_PACKAGES=$(sage-get-system-packages conda $BOOTSTRAP_PACKAGES)
75+
OPTIONAL_SYSTEM_PACKAGES=$(sage-get-system-packages conda $OPTIONAL_PACKAGES)
76+
SAGELIB_SYSTEM_PACKAGES=$(sage-get-system-packages conda $SAGELIB_PACKAGES)
77+
SAGELIB_OPTIONAL_SYSTEM_PACKAGES=$(sage-get-system-packages conda $SAGELIB_OPTIONAL_PACKAGES)
78+
DEVELOP_SYSTEM_PACKAGES=$(sage-get-system-packages conda $DEVELOP_PACKAGES)
79+
unset ENABLE_SYSTEM_SITE_PACKAGES
80+
81+
[ -n "$BOOTSTRAP_VERBOSE" ] && echo "## Translated to system:" && set | grep SYSTEM_PACKAGES=
82+
5383
echo >&2 $0:$LINENO: generate conda environment files
54-
(
55-
echo "name: sage-build"
56-
echo "channels:"
57-
echo " - conda-forge"
58-
echo " - nodefaults"
59-
echo "dependencies:"
60-
for pkg in $SYSTEM_PACKAGES; do
61-
echo " - $pkg"
62-
done
63-
echo " # Packages needed for ./bootstrap"
64-
for pkg in $BOOTSTRAP_PACKAGES; do
65-
echo " - $pkg"
66-
done
67-
) > environment.yml
6884

69-
(
70-
sed 's/name: sage-build/name: sage/' environment.yml
71-
echo " # Additional packages providing all dependencies for the Sage library"
72-
for pkg in $SAGELIB_SYSTEM_PACKAGES; do
73-
echo " - $pkg"
74-
done
75-
) > src/environment.yml
85+
(
86+
echo "name: sage-build"
87+
echo "channels:"
88+
echo " - conda-forge"
89+
echo " - nodefaults"
90+
echo "dependencies:"
91+
for pkg in $SYSTEM_PACKAGES; do
92+
echo " - $pkg"
93+
done
94+
echo " # Packages needed for ./bootstrap"
95+
for pkg in $BOOTSTRAP_SYSTEM_PACKAGES; do
96+
echo " - $pkg"
97+
done
98+
) > environment-template.yml
99+
(
100+
sed 's/name: sage-build/name: sage/' environment-template.yml
101+
echo " # Additional packages providing all dependencies for the Sage library"
102+
for pkg in $SAGELIB_SYSTEM_PACKAGES; do
103+
echo " - $pkg"
104+
done
105+
) > src/environment-template.yml
76106

77-
(
78-
sed 's/name: sage/name: sage-dev/' src/environment.yml
79-
echo " # Additional dev tools"
80-
for pkg in $DEVELOP_SYSTEM_PACKAGES; do
81-
echo " - $pkg"
82-
done
83-
) > src/environment-dev.yml
107+
(
108+
cat environment-template.yml
109+
echo " # optional packages"
110+
for pkg in $OPTIONAL_SYSTEM_PACKAGES; do
111+
echo " - $pkg"
112+
done
113+
) > environment-optional-template.yml
84114

85-
(
86-
cat environment.yml
87-
echo " # optional packages"
88-
for pkg in $OPTIONAL_SYSTEM_PACKAGES; do
89-
echo " - $pkg"
90-
done
91-
) > environment-optional.yml
115+
(
116+
sed 's/name: sage/name: sage-dev/' src/environment-template.yml
117+
echo " # Additional dev tools"
118+
for pkg in $DEVELOP_SYSTEM_PACKAGES; do
119+
echo " - $pkg"
120+
done
121+
) > src/environment-dev-template.yml
92122

93-
(
94-
cat src/environment.yml
95-
echo " # optional packages"
96-
for pkg in $OPTIONAL_SYSTEM_PACKAGES $SAGELIB_OPTIONAL_SYSTEM_PACKAGES; do
97-
echo " - $pkg"
98-
done
99-
) > src/environment-optional.yml
100-
(
101-
echo >&4 " - pip:"
102-
echo >&5 " - pip:"
103-
for PKG_BASE in $((sage-package list :standard: :optional: --has-file requirements.txt --no-file distros/conda.txt --no-file src; sage-package list :standard: :optional: --has-file install-requires.txt --no-file requirements.txt --no-file distros/conda.txt --no-file src) | sort); do
104-
PKG_SCRIPTS=build/pkgs/$PKG_BASE
105-
SYSTEM_PACKAGES_FILE=$PKG_SCRIPTS/requirements.txt
106-
if [ ! -f $SYSTEM_PACKAGES_FILE ]; then
107-
SYSTEM_PACKAGES_FILE=$PKG_SCRIPTS/install-requires.txt
108-
fi
109-
PKG_TYPE=$(cat $PKG_SCRIPTS/type)
110-
if grep -q SAGERUNTIME $PKG_SCRIPTS/dependencies $PKG_SCRIPTS/dependencies_order_only 2>/dev/null; then
111-
: # cannot install packages that depend on the Sage library
112-
else
113-
case "$PKG_BASE:$PKG_TYPE" in
114-
$DEVELOP_SPKG_PATTERN:*) FD=4;;
115-
*) FD=5;;
116-
esac
117-
${STRIP_COMMENTS} $SYSTEM_PACKAGES_FILE | while read -r line; do
118-
[ -n "$line" ] && echo >&$FD " - $line"
119-
done
120-
fi
123+
(
124+
cat src/environment-template.yml
125+
echo " # optional packages"
126+
for pkg in $OPTIONAL_SYSTEM_PACKAGES $SAGELIB_OPTIONAL_SYSTEM_PACKAGES; do
127+
echo " - $pkg"
128+
done
129+
) > src/environment-optional-template.yml
130+
131+
(
132+
echo >&4 " - pip:"
133+
echo >&5 " - pip:"
134+
for PKG_BASE in $(sage-package list :standard: :optional: --has-file requirements.txt --no-file distros/conda.txt --no-file src; sage-package list :standard: :optional: --has-file install-requires.txt --no-file requirements.txt --no-file distros/conda.txt --no-file src); do
135+
PKG_SCRIPTS=build/pkgs/$PKG_BASE
136+
SYSTEM_PACKAGES_FILE=$PKG_SCRIPTS/requirements.txt
137+
if [ ! -f $SYSTEM_PACKAGES_FILE ]; then
138+
SYSTEM_PACKAGES_FILE=$PKG_SCRIPTS/install-requires.txt
139+
fi
140+
PKG_TYPE=$(cat $PKG_SCRIPTS/type)
141+
if grep -q SAGERUNTIME $PKG_SCRIPTS/dependencies $PKG_SCRIPTS/dependencies_order_only 2>/dev/null; then
142+
: # cannot install packages that depend on the Sage library
143+
else
144+
case "$PKG_BASE:$PKG_TYPE" in
145+
$DEVELOP_SPKG_PATTERN:*) FD=4;;
146+
*:standard) FD="4 5";;
147+
*) FD=5;;
148+
esac
149+
${STRIP_COMMENTS} $SYSTEM_PACKAGES_FILE | while read -r line; do
150+
[ -n "$line" ] && for fd in $FD; do echo >&$fd " - $line"; done
151+
done
152+
fi
153+
done
154+
) 4>> /dev/null 5>> src/environment-optional-template.yml
155+
156+
for f in environment environment-optional src/environment src/environment-optional src/environment-dev; do
157+
for python_version in 3.9 3.10 3.11; do
158+
sed -E 's/^( *- *)python *$/\1python='$python_version'/' $f-template.yml > $f-$python_version.yml
121159
done
122-
) 4>> src/environment-dev.yml 5>> src/environment-optional.yml
160+
rm -f $f-template.yml
161+
done
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Trac #33642: For unknown reasons, without the version constraint, conda installs only 3.3.2
2-
"matplotlib>=3.5.1"
2+
matplotlib>=3.5.1

src/doc/en/installation/conda.rst

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,16 @@ from source as follows:
7575
- Create a new conda environment including all standard packages
7676
recognized by sage, and activate it::
7777

78-
$ conda env create --file environment.yml --name sage-build
78+
$ conda env create --file environment-3.11.yml --name sage-build
7979
$ conda activate sage-build
8080

81-
Alternatively, use ``environment-optional.yml`` in place of
81+
Alternatively, use ``environment-optional-3.11.yml`` in place of
8282
``environment.yml`` to create an environment with all standard and optional
8383
packages recognized by sage.
8484

85+
A different Python version can be selected by replacing ``3.11`` by ``3.9``
86+
or ``3.10`` in these commands.
87+
8588
- Then the SageMath distribution will be built using the compilers provided by Conda
8689
and using many packages installed by Conda::
8790

@@ -123,16 +126,15 @@ Here we assume that you are using a git checkout.
123126
- Create and activate a new conda environment with the dependencies of Sage
124127
and a few additional developer tools::
125128

126-
$ mamba env create --file src/environment-dev.yml --name sage-dev
129+
$ mamba env create --file src/environment-dev-3.11.yml --name sage-dev
127130
$ conda activate sage-dev
128131

129-
Alternatively, you can use ``src/environment.yml`` or
130-
``src/environment-optional.yml``, which will only install standard
132+
Alternatively, you can use ``src/environment-3.11.yml`` or
133+
``src/environment-optional-3.11.yml``, which will only install standard
131134
(and optional) packages without any additional developer tools.
132135

133-
By default, the most recent version of Python supported by Sage is
134-
installed. You can use the additional option ``python=3.9`` in the above
135-
``env create`` command to select another Python version (here 3.9).
136+
A different Python version can be selected by replacing ``3.11`` by ``3.9``
137+
or ``3.10`` in these commands.
136138

137139
- Install the build prerequisites and the Sage library::
138140

@@ -142,7 +144,7 @@ Here we assume that you are using a git checkout.
142144
- Verify that Sage has been installed::
143145

144146
$ sage -c 'print(version())'
145-
SageMath version 9.6.beta5, Release Date: 2022-03-12
147+
SageMath version 10.2.beta4, Release Date: 2023-09-24
146148

147149
Note that ``make`` is not used at all. All dependencies
148150
(including all Python packages) are provided by conda.
@@ -162,7 +164,7 @@ After editing any Cython files, rebuild the Sage library using::
162164

163165
In order to update the conda environment later, you can run::
164166

165-
$ mamba env update --file src/environment-dev.yml --name sage-dev
167+
$ mamba env update --file src/environment-dev-3.11.yml --name sage-dev
166168

167169
To build the documentation, use::
168170

0 commit comments

Comments
 (0)