Skip to content

MAINT: pin ruff rule set, lint whole repo, fix sum_spectra NameError - #8

Merged
physicien merged 3 commits into
mainfrom
development
Aug 17, 2026
Merged

MAINT: pin ruff rule set, lint whole repo, fix sum_spectra NameError#8
physicien merged 3 commits into
mainfrom
development

Conversation

@physicien

Copy link
Copy Markdown
Owner

Why

CI broke on Dependabot PR #7 (actions/setup-python v6 → v7). The bump was innocent: its whole diff is one line, and the failure was in the ruff check step.

The real cause is ruff version drift. CI installs ruff through the unpinned ruff>=0.4 extra and ran it with no configuration, so the rule set was whatever ruff defaulted to that day:

run ruff result
2026-07-08 (PRs #5, #6) 0.15.20 pass
2026-08-01 (PR #7) 0.16.1 30 errors

Same sources in both. main was equally broken, not just the PR.

What changed

  • pyproject.toml: select = ["E", "F", "W", "I"] and line-length = 80, matching the project convention. The rule set is now ours rather than ruff's shifting default, so a future release cannot reopen this. The 26 UP/SIM/RUF findings that broke CI are out of scope by construction, not suppressed. The longest line in src/ was already exactly 80, so the limit costs nothing.
  • Imports sorted across src/, tests/, tools/; 19 over-long test lines wrapped; two unused test imports dropped. No assertion or test logic changed.
  • ruff check src/ruff check ., so tests/ and tools/ are linted too.
  • Bug fix, tools/sum_spectra.py: the except IOError handler referenced filename, which is not defined (the loop variable is path; args.filename is the argparse list). A missing input file raised NameError from the handler instead of reporting the file, leaving sys.exit(1) unreachable. Invisible to CI because src/ was the only linted path.

Verification

Run with ruff 0.16.1, the version that broke CI:

  • ruff check . → passes on each of the three commits, against the lint command that commit's own ci.yml specifies.
  • pytest tests/ → 134 passed, identical to the pre-change baseline rebuilt on the unmodified tree, so the import reordering moved nothing.
  • sum_spectra.py exercised both paths: missing file now prints 'no_such_file.out' not found and exits 1; summing two copies of an ESD spectrum gives exactly 2×, and the output header and grid are unchanged.

Verification environment was a throwaway venv (Python 3.13.5, numpy 2.5.2, pandas 3.0.5, matplotlib 3.11.1, scipy 1.18.0), newer than the requirements/ pins, so this is "passes on current upstream" rather than a check against the pinned build.

Not addressed

CI still installs unpinned ruff>=0.4 while requirements/requirements-development.txt pins ruff==0.15.20. The rule-set pin makes ruff's defaults irrelevant, but a future release could still change behaviour inside E/F/W/I.

🤖 Generated with Claude Code

CI installed ruff via the unpinned `ruff>=0.4` extra and ran it with
no configuration, so the rule set was whatever ruff defaulted to that
day. ruff 0.16.1 lints under different defaults than 0.15.20 did and
reported 30 errors on unchanged sources, breaking CI on an unrelated
Dependabot PR.

Select E, F, W, I explicitly and set line-length to 80, matching the
project convention, so the rule set no longer moves with the tool.
The longest line in src/ was already exactly 80, so the limit costs
nothing.

Sorts imports across src/, tests/ and tools/, wraps 19 over-long test
lines, and drops two unused test imports. No assertion or test logic
is changed.
The `except IOError` handler referenced `filename`, which is not
defined: the loop variable is `path` and `args.filename` is the
argparse list. A missing input file therefore raised NameError from
the handler instead of reporting the file, and left sys.exit(1)
unreachable.
Extends `ruff check src/` to `ruff check .`, so tests/ and tools/ are
linted too. src/ being the only linted path is why an undefined name
went unnoticed in tools/.
@physicien
physicien merged commit dd081e8 into main Aug 17, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant