Skip to content

Reformat the codebase with ruff format - #638

Closed
mdickinson wants to merge 3 commits into
mainfrom
ruff-format
Closed

mdickinson wants to merge 3 commits into
mainfrom
ruff-format

Conversation

@mdickinson

Copy link
Copy Markdown
Member

Part of #636, stacked on #637. Based on ruff-config, so the Files tab shows
only this change; GitHub will retarget it to main when #637 merges.

Two commits, ordered so that each one is green:

  1. The reformat. Mechanical — the entire diff is the output of
    ruff format ., touching .py files only. 133 files, +196/-435.
  2. One line adding ruff format --check --diff to the style workflow.
    Separated from the reformat so the check is only turned on once the
    codebase already satisfies it, rather than merging something red.

What's actually in the diff

Almost all of it is docstring normalization:

-""" An application event. """
-
+"""An application event."""

That is the same change black wants at its current version, so it was coming
either way — see #632. The remainder is lines rejoined at the new length of
88.

Checks run locally

  • uv run --locked --only-group style -m ruff check . — passes
  • uv run --locked --only-group style -m ruff format --check . — 215 files
    already formatted
  • uv run -m pytest — 178 passed

This PR was created with the assistance of an AI coding agent.

🤖 Generated with Claude Code

mdickinson and others added 3 commits August 6, 2026 20:12
Style checks are now a single tool. The lint side is configured to be a
faithful port of the old flake8 and isort setup, so this commit leaves
the formatting of the codebase untouched and `ruff check` passes as-is;
the reformat that `ruff format` wants is a separate change.

The copyright header check moves from flake8-ets to ruff's CPY001 rule.
The header text lives in ruff-copyright.toml as a regular expression, so
the check covers the full wording and not just the copyright line. In
place of the old strict-style workflow, which compared each file's end
year against the current year, CPY001 holds every file to the configured
year and a new check-copyright-year workflow holds that year to the
current one.

Two settings are worth calling out. `known-third-party` keeps the acme
and attractors demo packages classified as they were under isort, which
avoids a re-sort that would strand their "# Local imports." comments.
The ruff dependency is upper-bounded because ruff changes formatting in
minor releases, so an unpinned bump would reformat the codebase.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Mechanical: the entire diff is the output of `ruff format .`. Almost all
of it is docstring normalization, which black would also have applied at
its current version; the rest is lines rejoined at the new length of 88.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Kept separate from the reformat so that every commit is green: the
codebase is already formatted by the time this check is turned on.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
mdickinson added a commit that referenced this pull request Aug 7, 2026
Closes #636. This is the first of two PRs; the reformat that `ruff
format`
wants is #638, stacked on this one.

Style checks become a single tool. The lint side is configured as a
faithful
port of the old flake8 and isort setup, so **this PR leaves the
formatting of
the codebase untouched** and `ruff check` passes as-is. That keeps the
PR
reviewable, and means nothing has to be merged red — `ruff format
--check` is
turned on in the follow-up, in the same change that makes it pass.

## The copyright check

flake8-ets is replaced by ruff's `CPY001` rule, configured by the
`notice-rgx` setting in `pyproject.toml`.

The aim is to keep flake8-ets's behaviour rather than improve on it,
since
flake8-ets already matched the full nine-line header. `CPY001` compares
a
regular expression, not a fixed string, so the header text is written
with its
parentheses and periods escaped; a leading `\A` anchors it to the start
of the
file, matching flake8-ets's `re.match`; and `min-file-size = 1` exempts
empty
files, which flake8-ets special-cased.

Two differences are worth review:

- The year range is written out verbatim as `2007-2026`, so the **start
year
is now enforced too**. flake8-ets accepted any start year — both
`2020-2026`
  and a bare `2026` passed it — and checked only the end year. All 186
non-empty source files already use `2007`, so nothing changes today, but
a
  new file must use the same range rather than its own.
- `CPY001` reports one generic "Missing copyright notice at top of file"
for
any mismatch. That is **less specific than flake8-ets**, which separated
a
wording failure (H101) from a wrong year (H102) and named the actual and
expected years. The `check-copyright-year` workflow below covers the
case
that message mattered most for — the year rolling over — but a
hand-mangled
  header now gets a vaguer diagnostic.

The nudge to update the year is preserved, in two halves that compose to
the
same guarantee the strict-style workflow gave:

- `CPY001` holds every source file to the year configured in
  `pyproject.toml`;
- the new `check-copyright-year` workflow holds that configured year to
the
  current year.

The second half is a plain `grep` against `date --utc +%Y`, so it needs
no
Python and no ruff. The old `check-style-strict.yml` is removed.

## Two settings worth calling out

`known-third-party = ['acme', 'attractors']` keeps the demo packages
classified as isort had them. Without it ruff treats them as first-party
and
re-sorts 11 files, stranding their `# Local imports.` comments above the
wrong
imports. With it, `ruff check` reports zero violations on the tree as it
stands.

The ruff dependency is upper-bounded to `~= 0.16.0`. Ruff confines
formatting
changes to minor releases, so an unpinned bump would silently reformat
the
codebase — exactly what #632 is currently doing with black 26. Raising
the
bound in future is a deliberate change that carries its own reformat.

## Other notes

- Line length moves from 79 to ruff's default of 88.
- None of flake8's `E203`/`E266`/`W503` ignores are needed; those rules
are
preview-only in ruff. `*/api.py: F401` carries over as
`per-file-ignores`.
- Coverage is unchanged: ruff lints all 212 tracked `.py` files.
- The `style` job keeps its name, so branch protection needs no changes.
- #632 is superseded by this work, and there is a second reason to
prefer
  this route. #632 is a Dependabot **security** update: there is an open
high-severity advisory against black covering `>= 24.3.0, < 26.3.1`, and
the
pinned `black ~= 24.3` resolves to 24.10.0, inside that range. Removing
black from `uv.lock` altogether resolves it without taking black 26 and
the
  reformat it brings. If this PR stalls, #632 remains the fallback.

## Checks run locally

- `uv run --locked --only-group style -m ruff check .` — passes
- `uv run -m pytest` — 178 passed

*This PR was created with the assistance of an AI coding agent.*

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Base automatically changed from ruff-config to main August 7, 2026 08:38
@mdickinson

Copy link
Copy Markdown
Member Author

Superseded by #642, which is built from scratch on current main rather than rebased. This branch predated the review changes on #637, so recreating it clean makes it easier to verify that the diff is exactly ruff format output.

@mdickinson mdickinson closed this Aug 7, 2026
@mdickinson
mdickinson deleted the ruff-format branch August 7, 2026 08:42
mdickinson added a commit that referenced this pull request Aug 7, 2026
Part of #636, and the follow-up to #637. Replaces #638, which was
branched
before #637's review changes; this one is built from scratch on current
`main`
so that it is exactly reproducible.

## How to reproduce this PR

```bash
git checkout main            # afa89dd
git checkout -b ruff-reformat
uv run --locked --only-group style -m ruff format .   # commit 1
# add `ruff format --check --diff .` to check-style.yml   # commit 2
```

Two commits, ordered so that each one is green on its own:

1. **The reformat** — mechanical, the entire diff is the output of
   `ruff format .`. 133 files, +196/-435, `.py` files only.
2. **One line** adding `ruff format --check --diff` to the style
workflow.
   Separated from the reformat so the check is only turned on once the
   codebase already satisfies it, rather than merging something red.

## What's actually in the diff

Almost all of it is docstring normalization:

```diff
-""" An application event. """
-
+"""An application event."""
```

That is the same change black wants at its current version, so it was
coming
either way — see #632. The remainder is lines rejoined at the length of
88 set
in #637.

## Checks run locally, on each commit separately

| | `ruff check` | `ruff format --check` |
| --- | --- | --- |
| Reformat commit | All checks passed | 215 files already formatted |
| CI commit | All checks passed | 215 files already formatted |

Also `uv run -m pytest` — 178 passed — and the `check-copyright-year`
grep
passes (2026/2026).

*This PR was created with the assistance of an AI coding agent.*

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
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