ci: fix sage CLI invocations for conda-forge's sage (no --preparse/--python flags)
CI / lint (push) Failing after 14s
CI / test (push) Skipped

This commit is contained in:
julian
2026-07-26 14:18:17 +02:00
parent 3e6660a414
commit d649d5047f
+21 -7
View File
@@ -24,17 +24,31 @@ jobs:
# parse it, and prepends the `from sage.all import *` that `sage` # parse it, and prepends the `from sage.all import *` that `sage`
# normally injects at runtime, so Sage's globals (ZZ, var, matrix, ...) # normally injects at runtime, so Sage's globals (ZZ, var, matrix, ...)
# resolve instead of looking like undefined names. # resolve instead of looking like undefined names.
#
# The conda-forge `sage` CLI has no `--preparse` flag (unlike the
# classical sage script the image was originally written against), so
# this calls the same preparser Sage itself uses, directly in Python.
run: | run: |
set -e python - <<'PYEOF'
for f in $(find . -name "*.sage" -not -path "./playground/*"); do import pathlib
sage --preparse "$f" from sage.repl.preparse import preparse_file
printf 'from sage.all import * # noqa: F401,F403\n%s\n' "$(cat "${f}.py")" > "${f}.py"
done for f in pathlib.Path(".").rglob("*.sage"):
if f.parts and f.parts[0] == "playground":
continue
out = preparse_file(f.read_text())
f.with_suffix(f.suffix + ".py").write_text(
"from sage.all import * # noqa: F401,F403\n" + out
)
PYEOF
- name: ruff check - name: ruff check
# --no-respect-gitignore: *.sage.py is gitignored (it's generated, see # --no-respect-gitignore: *.sage.py is gitignored (it's generated, see
# the previous step) but that's exactly what we need to lint here. # the previous step) but that's exactly what we need to lint here.
run: sage --python -m ruff check --no-respect-gitignore . # `python` here is the conda env's own interpreter -- it already has
# sage/ruff/pytest importable, `sage --python` isn't a real flag on
# the conda-forge sage CLI.
run: python -m ruff check --no-respect-gitignore .
test: test:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -47,4 +61,4 @@ jobs:
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Run tests - name: Run tests
run: sage --python -m pytest tests/ run: python -m pytest tests/