Adopt ruff for linting and formatting - #233
Open
kroenlein wants to merge 2 commits into
Open
Conversation
Add a [tool.ruff] configuration to pyproject.toml, then apply ruff's lint fixes and formatter across gemd and tests. tox.ini keeps the flake8 rules unchanged, so both linters run green on the same tree. The result is stable under editor-on-save: `ruff check --fix` and `ruff format` each make no further changes. The config mirrors flake8 wherever flake8 has an opinion. It selects E, W, F and D to match pycodestyle, pyflakes and flake8-docstrings, and names E231 and E275 individually because ruff still treats those two as preview rules. It adds isort, which flake8 never checked. Where flake8 is silent, it follows ruff's defaults, so the pydocstyle convention stays unset and 15 more D rules apply than flake8 enforced. Hand-fix the places where the formatter's output broke a flake8 rule. pycodestyle exempts backslash continuations from W503, and the formatter rewrites those continuations as parentheses, so eight long boolean conditions needed restructuring into named intermediate values. Two slices in gemd/units/impl.py get their bounds hoisted into locals, which keeps the formatter from spacing the colon (E203). One TypeVar call is exploded so its trailing noqa comment fits inside 99 characters, because the formatter excludes such comments when measuring width and flake8 counts them. Fix two real defects the wider rule set exposed. tests/builders used BaseValue in annotations without importing it. The parameter type in BaseTemplate._homogenize_ranges wrapped across two lines, which hid its description from the numpy-section parser and from Sphinx. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Rewrite every str.format call site in gemd and tests as an f-string. The rendered strings are unchanged, since both forms dispatch to __format__. Ruff's UP032 rule generated 44 of these. It skipped two call sites, which this commit rewrites by hand: each nested a double-quoted string inside its format arguments, and an f-string expression cannot reuse the enclosing quote character before Python 3.12. Both now use single quotes inside the expression, which Python 3.9 accepts. Leave UP032 out of the ruff rule selection. This is a one-time improvement rather than a standing rule. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
kroenlein
marked this pull request as ready for review
September 10, 2026 21:36
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.
No-op PR that updates formatting so that it confirms to both ruff and flake8.