From 80072b291f8572798ae170aa1baaec58af9fa6d2 Mon Sep 17 00:00:00 2001 From: Julian Piribauer Date: Sun, 26 Jul 2026 14:42:06 +0200 Subject: [PATCH] Ignore EOF blank line check --- .gitea/preparse.sh | 15 +++++++++++++++ .gitea/workflows/ci.yml | 7 +------ pyproject.toml | 5 ++++- 3 files changed, 20 insertions(+), 7 deletions(-) create mode 100755 .gitea/preparse.sh diff --git a/.gitea/preparse.sh b/.gitea/preparse.sh new file mode 100755 index 0000000..13c706f --- /dev/null +++ b/.gitea/preparse.sh @@ -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 diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 655193e..4c89a0d 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -24,12 +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. - run: | - 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 + run: .gitea/preparse.sh - name: ruff check # --no-respect-gitignore: *.sage.py is gitignored (it's generated, see diff --git a/pyproject.toml b/pyproject.toml index 4659824..d9ee759 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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