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

Improve conda setup #38728

Merged
merged 8 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .devcontainer/onCreate-conda.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
set -e

# Create conda environment
conda install mamba -n base -c conda-forge -y
mamba env create --file src/environment-dev-3.11-linux.yml || mamba env update --file src/environment-dev-3.11-linux.yml
conda config --env --add channels conda-forge
conda config --env --set channel_priority strict
conda update -y --all --override-channels -c conda-forge
conda install mamba=1 -n base -y
mamba env create -y --file environment-dev-3.11-linux.yml || mamba env update -y --file environment-dev-3.11-linux.yml
conda init bash

# Build sage
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
with:
path: ~/conda_pkgs_dir
key:
${{ runner.os }}-conda-${{ hashFiles('src/environment-3.11.yml') }}
${{ runner.os }}-conda-${{ hashFiles('environment-3.11.yml') }}

- name: Setup Conda environment
uses: conda-incubator/setup-miniconda@v3
Expand All @@ -70,7 +70,7 @@ jobs:
channels: conda-forge
channel-priority: true
activate-environment: sage
environment-file: src/${{ matrix.conda-env }}-${{ matrix.python }}-${{ startsWith(matrix.os, 'macos') && (startsWith(runner.arch, 'ARM') && 'macos' || 'macos-x86_64') || 'linux' }}.yml
environment-file: ${{ matrix.conda-env }}-${{ matrix.python }}-${{ startsWith(matrix.os, 'macos') && (startsWith(runner.arch, 'ARM') && 'macos' || 'macos-x86_64') || 'linux' }}.yml

- name: Print Conda environment
shell: bash -l {0}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-meson.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
with:
path: ~/conda_pkgs_dir
key:
${{ runner.os }}-conda-${{ hashFiles('src/environment-3.11-linux.yml') }}
${{ runner.os }}-conda-${{ hashFiles('environment-3.11-linux.yml') }}

- name: Compiler cache
uses: hendrikmuhs/ccache-action@v1.2
Expand All @@ -55,7 +55,7 @@ jobs:
channels: conda-forge
channel-priority: true
activate-environment: sage
environment-file: src/environment-${{ matrix.python }}-${{ startsWith(matrix.os, 'macos') && (startsWith(runner.arch, 'ARM') && 'macos' || 'macos-x86_64') || 'linux' }}.yml
environment-file: environment-${{ matrix.python }}-${{ startsWith(matrix.os, 'macos') && (startsWith(runner.arch, 'ARM') && 'macos' || 'macos-x86_64') || 'linux' }}.yml

- name: Print Conda environment
shell: bash -l {0}
Expand Down
45 changes: 34 additions & 11 deletions .github/workflows/conda-lock-update.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,53 @@
import subprocess

script_dir = Path(__file__).resolve().parent
root_dir = script_dir / '..' / '..'
root_dir = script_dir / ".." / ".."

subprocess.run([str(root_dir / "bootstrap-conda")])

platforms = {
"linux-64": "linux",
"linux-aarch64": "linux-aarch64",
"osx-64": "macos-x86_64",
"osx-arm64": "macos"
#"win-64": "win",
"osx-arm64": "macos",
# "win-64": "win",
}
pythons = ["3.9", "3.10", "3.11"]
tags = ["", "-dev"]
sources = ["", "src"]

for platform_key, platform_value in platforms.items():
for python in pythons:
for tag in tags:
for src in sources:
env_file = root_dir / src / f"environment{tag}-{python}.yml"
lock_file = root_dir / src / f"environment{tag}-{python}-{platform_value}"
env_file = root_dir / f"environment{tag}-{python}.yml"
lock_file = root_dir / f"environment{tag}-{python}-{platform_value}"
lock_file_gen = root_dir / f"environment{tag}-{python}-{platform_value}.yml"

if not env_file.exists():
continue
if not env_file.exists():
continue

print(f"Updating lock file for {env_file} at {lock_file}", flush=True)
subprocess.run(["conda-lock", "--channel", "conda-forge", "--kind", "env", "--platform", platform_key, "--file", str(env_file), "--lockfile", str(lock_file), "--filename-template", str(lock_file)])
print(f"Updating lock file for {env_file} at {lock_file_gen}", flush=True)
subprocess.run(
[
"conda-lock",
"--mamba",
"--channel",
"conda-forge",
"--kind",
"env",
"--platform",
platform_key,
"--file",
str(env_file),
"--lockfile",
str(lock_file),
"--filename-template",
str(lock_file),
],
check=True,
)

# Add conda env name to lock file at beginning
with open(lock_file_gen, "r+") as f:
content = f.read()
f.seek(0, 0)
f.write(f"name: sage{tag}\n{content}")
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@
/src/lib/pkgconfig

# Environment files generated by bootstrap-conda.
# The files without Python version are no longer generated
# The files without Python version and in src are no longer generated
# but may still be in users' directories.
/environment.yml
/environment-3.9.yml
/environment-3.10.yml
/environment-3.11.yml
/environment-dev-3.9.yml
/environment-dev-3.10.yml
/environment-dev-3.11.yml
/environment-optional.yml
/environment-optional-3.9.yml
/environment-optional-3.10.yml
Expand Down
2 changes: 1 addition & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tasks:
- name: Setup
# Create conda environment, then configure and build sage
init: >-
&& mamba env create --file src/environment-dev-3.11-linux.yml --prefix venv
&& mamba env create --file environment-dev-3.11-linux.yml --prefix venv
&& conda config --append envs_dirs $(pwd)
&& conda activate $(pwd)/venv
&& ./bootstrap
Expand Down
4 changes: 1 addition & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
// This settings file is not ignored by git. It should be kept in sync with
// the trac repo.
"python.defaultInterpreterPath": "./venv/bin/python3",
// This settings file is not ignored by git.
"files.exclude": {
"**/__pycache__": true,
"src/**/*.cpp": true,
Expand Down
3 changes: 0 additions & 3 deletions bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,6 @@ save () {
src/doc/en/installation/*.txt \
$(find src/doc/en/reference/spkg -name index.rst -prune -o -maxdepth 1 -name "*.rst" -print) \
environment-3.[89].yml environment-3.1[0-9].yml \
src/environment-3.[89].yml src/environment-3.1[0-9].yml \
environment-optional-3.[89].yml environment-optional-3.1[0-9].yml \
src/environment-optional-3.[89].yml src/environment-optional-3.1[0-9].yml \
src/Pipfile \
src/pyproject.toml \
src/requirements.txt \
Expand Down
50 changes: 5 additions & 45 deletions bootstrap-conda
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ unset ENABLE_SYSTEM_SITE_PACKAGES
echo >&2 $0:$LINENO: generate conda environment files

(
echo "name: sage-build"
echo "name: sage"
echo "channels:"
echo " - conda-forge"
echo " - nodefaults"
Expand All @@ -106,58 +106,18 @@ echo >&2 $0:$LINENO: generate conda environment files
for pkg in $SAGELIB_SYSTEM_PACKAGES; do
echo " - $pkg"
done
) > src/environment-template.yml

(
cat environment-template.yml
echo " # optional packages"
for pkg in $OPTIONAL_SYSTEM_PACKAGES; do
echo " - $pkg"
done
) > environment-optional-template.yml
) > environment-template.yml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tobiasdiez This breaks the build.

https://unix.stackexchange.com/questions/110490/why-does-the-command-shuf-file-file-leave-an-empty-file-but-similar-commands

On the left hand side you read from environment-template.yml, but on the right hand side you > into that same file. On my machine the file is erased before it's read.

Fortunately the fix is simple: since both are actually the same file, you can just combine the two blocks into one.


(
sed 's/name: sage/name: sage-dev/' src/environment-template.yml
sed 's/name: sage/name: sage-dev/' environment-template.yml
echo " # Additional dev tools"
echo " - conda-lock"
for pkg in $DEVELOP_SYSTEM_PACKAGES; do
echo " - $pkg"
done
) > src/environment-dev-template.yml

(
cat src/environment-template.yml
echo " # optional packages"
for pkg in $OPTIONAL_SYSTEM_PACKAGES $SAGELIB_OPTIONAL_SYSTEM_PACKAGES; do
echo " - $pkg"
done
) > src/environment-optional-template.yml

(
echo >&4 " - pip:"
echo >&5 " - pip:"
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 version_requirements.txt --no-file requirements.txt --no-file distros/conda.txt --no-file src); do
eval PKG_SCRIPTS=\$path_$PKG_BASE PKG_TYPE=\$type_$PKG_BASE
SYSTEM_PACKAGES_FILE=$PKG_SCRIPTS/requirements.txt
if [ ! -f $SYSTEM_PACKAGES_FILE ]; then
SYSTEM_PACKAGES_FILE=$PKG_SCRIPTS/version_requirements.txt
fi
if grep -q SAGERUNTIME $PKG_SCRIPTS/dependencies $PKG_SCRIPTS/dependencies_order_only 2>/dev/null; then
: # cannot install packages that depend on the Sage library
else
case "$PKG_BASE:$PKG_TYPE" in
$DEVELOP_SPKG_PATTERN:*) FD=4;;
*:standard) FD="4 5";;
*) FD=5;;
esac
${STRIP_COMMENTS} $SYSTEM_PACKAGES_FILE | while read -r line; do
[ -n "$line" ] && for fd in $FD; do echo >&$fd " - $line"; done
done
fi
done
) 4>> /dev/null 5>> src/environment-optional-template.yml
) > environment-dev-template.yml

for f in environment environment-optional src/environment src/environment-optional src/environment-dev; do
for f in environment environment-dev; do
for python_version in 3.9 3.10 3.11; do
sed -E 's/^( *- *)python *$/\1python='$python_version'/' $f-template.yml > $f-$python_version.yml
done
Expand Down
1 change: 0 additions & 1 deletion condarc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
channel_priority: strict
channels:
- conda-forge
- defaults
Loading
Loading