Skip to content

Replace black, isort and flake8 with ruff - #637

Merged
mdickinson merged 4 commits into
mainfrom
ruff-config
Aug 7, 2026
Merged

mdickinson merged 4 commits into
mainfrom
ruff-config

Conversation

@mdickinson

@mdickinson mdickinson commented Aug 6, 2026 •

Copy link
Copy Markdown
Member

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.
  • Bump black from 24.10.0 to 26.5.1 #632 is superseded by this work, and there is a second reason to prefer
    this route. Bump black from 24.10.0 to 26.5.1 #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, Bump black from 24.10.0 to 26.5.1 #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

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>
mdickinson and others added 3 commits August 6, 2026 21:12
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The separate file was only worth having if ruff could read the header
text verbatim from it. It can't - CPY001 takes a regular expression from
a config value either way - so the split bought nothing but an extra
file. The current-year check greps pyproject.toml instead.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the project’s style toolchain from black/isort/flake8 (plus flake8-ets) to ruff, including a ruff-based copyright header check and a lightweight workflow to keep the configured copyright year in sync.

Changes:

  • Replace black/isort/flake8/flake8-ets with ruff in dependency groups, lockfile, and CI style workflow.
  • Port lint/import-sorting/copyright-header configuration into pyproject.toml under [tool.ruff].
  • Replace the strict style workflow’s year check with a dedicated check-copyright-year workflow.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
uv.lock Removes black/isort/flake8(+deps) and adds ruff to locked dev/style dependencies.
pyproject.toml Drops black/isort config and introduces ruff configuration (rules, isort sections, copyright regex).
CHANGES.rst Records the tooling migration in the changelog.
AGENTS.md Updates contributor guidance to reference ruff instead of black/isort/flake8.
.github/workflows/check-style.yml Switches CI style job to run ruff check.
.github/workflows/check-copyright-year.yml Adds CI guard ensuring the configured copyright end year matches the current year.
.github/workflows/check-style-strict.yml Removes the old strict workflow that relied on flake8-ets year checks.
.flake8 Removes obsolete flake8 configuration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread AGENTS.md
Comment on lines +53 to 58
Style is enforced by ruff, provided by the `dev` group. Run both checks:

```bash
uv run -m black --check --diff .
uv run -m isort --check --diff .
uv run -m flake8 .
uv run -m ruff check .
uv run -m ruff format --check --diff .
```

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a concern - the reformat PR will be merged almost immediately after this one.

@mdickinson
mdickinson merged commit afa89dd into main Aug 7, 2026
27 checks passed
@mdickinson
mdickinson deleted the ruff-config branch August 7, 2026 08:38
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>
mdickinson added a commit that referenced this pull request Aug 7, 2026
…ode (#644)

Closes #643.

Changelog entries in `CHANGES.rst` end with the number of the pull
request
that made the change, not the issue it closes. Nothing said so, and
`AGENTS.md` had no changelog section at all, so this adds one.

Behind that, Claude Code reads `CLAUDE.md`, not `AGENTS.md`, and this
repository had neither — so nothing in `AGENTS.md` reached it, including
the
existing rule that a PR made with agent assistance has to say so. The
new
`CLAUDE.md` imports `AGENTS.md` with `@AGENTS.md` rather than repeating
any
of it, so there's no second copy to keep in sync.

Also corrects the ruff entry, which cited issue #636 where #637 is the
PR.

I checked the other 257 `#N` references in `CHANGES.rst` against the
GitHub
API. Every trailing reference is a PR except one in 4.5.0 (`(#37)`), and
the
two mentions of `#417` are deliberate inline prose — "which caused the
issue
#417", with the PR number correctly in the trailing parens. So the
convention
is already near-universal; this just writes it down. I've left the 4.5.0
entry
alone as long-released history.

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

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
larsoner added a commit to larsoner/envisage that referenced this pull request Aug 7, 2026
main replaced black, isort and flake8 with ruff (enthought#637) and reformatted with
it (enthought#642) after this branch was cut, so the two files it touches were still
formatted to black's 79 columns.  Run ruff over them.

main also documented the changelog conventions (enthought#644), so add the entries
this PR owes: the fix under Fixes, and the plugin's first tests under Tests,
beside the Pygments dependency (enthought#641) they turned up.
mdickinson added a commit that referenced this pull request Aug 7, 2026
Closes #653.

Prepares the 8.0.1 release:

* Retitle the in-development changelog section from `8.1.0` to `8.0.1`,
and
  replace the `Released: YYYY-MM-DD` placeholder with today's date.
* Add the overview, in the style used for earlier bugfix releases, and
credit
  contributors since 8.0.0 under `Thanks to`.
* Bump the version in `pyproject.toml` from 8.0.0 to 8.0.1, and refresh
  `uv.lock`, which pins the project's own version. (8.0.0 predated the
  lockfile, so this step is new since the last release.)

Three PRs merged since the 8.0.0 tag had no changelog entry, so this
adds
them: the ruff reformat (#642), folded into the entry for the PR that
configured ruff (#637), the `edm.yaml` move (#634), and the
`pypa/gh-action-pypi-publish` bump (#633). #650 is deliberately left
out,
since it only edited the changelog. Happy to drop #633 and #634 if you'd
rather keep the release notes to things a reader of them would act on.

Pre-flight, beyond CI: `uv build` and `twine check --strict` both pass,
and
`uv sync --locked` confirms the refreshed lockfile.

Diffing the 8.0.1 artifacts against the released 8.0.0 ones shows one
difference that isn't explained by the changes since 8.0.0: the sdist
now
carries a `pyproject.toml.orig` beside a `pyproject.toml` that has been
rewritten and stripped of its comments. That is `uv_build` working as
designed — since uv 0.12.0 it always rewrites the sdist's
`pyproject.toml`
as TOML 1.0, so that older build frontends can consume it, and preserves
the
original alongside. The two parse to identical data. It arrived with
#628,
along with the switch to `uv_build`, and needs no action.

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

---------

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.

Replace black, isort and flake8 with ruff

2 participants