Compare commits

..
2 Commits
3 changed files with 20 additions and 18 deletions
+15
View File
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
# Reproduces the CI "Preparse .sage files" step locally, so `ruff check` sees
# the same generated *.sage.py files that the pipeline lints. Run this before
# `sage --python -m ruff check --no-respect-gitignore .` to catch issues that
# only show up in the generated output (e.g. missing trailing newlines).
#
# The generated files are gitignored; clean them up afterwards with:
# git clean -x sage/ playground/
set -e
for f in $(find . -name "*.sage" -not -path "./playground/*"); do
sage --preparse "$f"
printf 'from sage.all import * # noqa: F401,F403\n%s\n' "$(cat "${f}.py")" > "${f}.py"
done
+1 -17
View File
@@ -24,23 +24,7 @@ jobs:
# parse it, and prepends the `from sage.all import *` that `sage`
# normally injects at runtime, so Sage's globals (ZZ, var, matrix, ...)
# 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: |
python - <<'PYEOF'
import pathlib
from sage.repl.preparse import preparse_file
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
run: .gitea/preparse.sh
- name: ruff check
# --no-respect-gitignore: *.sage.py is gitignored (it's generated, see
+4 -1
View File
@@ -23,7 +23,10 @@ ignore = [
# so trailing-whitespace warnings fire mechanically on almost every line
# with a number in it -- not something `ruff format` could fix anyway,
# since it wouldn't change the .sage source that generated it.
"*.sage.py" = ["F403", "F405", "F821", "E741", "E402", "E702", "I001", "W291", "W293"]
# - W292: whether the reconstructed file ends in a real trailing newline
# depends on how many blank lines the preparser appends, which varies by
# Sage version -- not something worth pinning tool versions over.
"*.sage.py" = ["F403", "F405", "F821", "E741", "E402", "E702", "I001", "W291", "W293", "W292"]
# tests/test_smoke.py does `from sage.all import *` and `load(...)` a .sage
# file to get at its classes -- the same dynamic-namespace situation as