MAINT: pin ruff rule set, lint whole repo, fix sum_spectra NameError - #8
Merged
Conversation
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/.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
CI broke on Dependabot PR #7 (
actions/setup-pythonv6 → v7). The bump was innocent: its whole diff is one line, and the failure was in theruff checkstep.The real cause is ruff version drift. CI installs ruff through the unpinned
ruff>=0.4extra and ran it with no configuration, so the rule set was whatever ruff defaulted to that day:Same sources in both.
mainwas equally broken, not just the PR.What changed
pyproject.toml:select = ["E", "F", "W", "I"]andline-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 insrc/was already exactly 80, so the limit costs nothing.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 ., sotests/andtools/are linted too.tools/sum_spectra.py: theexcept IOErrorhandler referencedfilename, which is not defined (the loop variable ispath;args.filenameis the argparse list). A missing input file raisedNameErrorfrom the handler instead of reporting the file, leavingsys.exit(1)unreachable. Invisible to CI becausesrc/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 ownci.ymlspecifies.pytest tests/→ 134 passed, identical to the pre-change baseline rebuilt on the unmodified tree, so the import reordering moved nothing.sum_spectra.pyexercised both paths: missing file now prints'no_such_file.out' not foundand 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.4whilerequirements/requirements-development.txtpinsruff==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