Compare commits
2
Commits
d649d5047f
...
53a1eb6ca7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
53a1eb6ca7 | ||
|
|
80072b291f |
Executable
+15
@@ -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
@@ -24,23 +24,7 @@ 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.
|
||||||
#
|
run: .gitea/preparse.sh
|
||||||
# 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
|
|
||||||
|
|
||||||
- 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
|
||||||
|
|||||||
+4
-1
@@ -23,7 +23,10 @@ ignore = [
|
|||||||
# so trailing-whitespace warnings fire mechanically on almost every line
|
# so trailing-whitespace warnings fire mechanically on almost every line
|
||||||
# with a number in it -- not something `ruff format` could fix anyway,
|
# with a number in it -- not something `ruff format` could fix anyway,
|
||||||
# since it wouldn't change the .sage source that generated it.
|
# 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
|
# 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
|
# file to get at its classes -- the same dynamic-namespace situation as
|
||||||
|
|||||||
Reference in New Issue
Block a user