Skip to content

Format the tree with ruff, and gate it in CI - #38

Merged
huangziwei merged 1 commit into
masterfrom
ruff-format-repo
Aug 18, 2026
Merged

huangziwei merged 1 commit into
masterfrom
ruff-format-repo

Conversation

@huangziwei

Copy link
Copy Markdown
Collaborator

ruff format over the whole repo — 41 of 46 files. The five already formatted
are the ones somebody had run a formatter over at some point, which is why the
tree currently has two styles in it.

Nothing here changes behaviour, and the diff is large enough that saying so
is not worth much without a check. See "Proof" below.

The settings, and why they are not the defaults

Pinned in pyproject.toml rather than left implicit, so a change to ruff's own
defaults is a deliberate edit here rather than a repo-wide reformat nobody asked
for.

line-length = 88 — ruff's default, and what the already-formatted files
use. 100 and 120 were about the same diff size (2871 and 2611 changed lines
against 2975), so this is not the axis that matters.

skip-magic-trailing-comma = true — this one is a real choice. Ruff, like
black, treats a trailing comma as "keep this exploded". The trailing commas in
this tree are a habit of writing [8, ] and [params[i], ], not a request, and
respecting them produces:

Cinvs = [
    smoothness_kernel(
        [
            params[i],
        ],
        df[i],
    )[1]
    for i in range(len(df))
]

against

Cinvs = [smoothness_kernel([params[i]], df[i])[1] for i in range(len(df))]

isort.split-on-trailing-comma = false comes with it; ruff warns if they
disagree.

extend-exclude = ["*.md"] — ruff formats python blocks inside markdown.
In the README that turns

lnp.add_design_matrix(X_dev, name="stimulus")  # basis will automatically apply to dev set

into a three-line call, because the trailing comment pushes it past 88. Worse
documentation for the sake of a limit the block is not compiled under.

ruff>=0.16,<0.17 in the dev group. It is a CI gate now, and an unpinned
formatter means a release can turn that gate red on a tree nobody touched.

Proof that it changes nothing

Every .py file was parsed before and after and the ASTs compared:

  • 36 of 44 produce a byte-identical ast.dump.
  • The other 8 have identical structure — comparing ASTs with every string
    constant blanked out gives an exact match — and differ only in whitespace
    inside docstrings, which is the formatter stripping trailing spaces and
    reindenting. For all of them, "".join(old.split()) == "".join(new.split()).

Plus: the suite is 69 passed before and after, and ruff check reports the
same 243 findings both ways, so the formatter neither fixed nor introduced a
single lint issue.

CI

Adds a format job running ruff format --check ..

It does not add ruff check. There are 243 lint findings in the tree, and a
gate that passes because it is not looking is worth nothing. That job goes in
with the change that clears them, which is the next PR — and it is a much less
mechanical one than this: 26 F401 unused imports where some are deliberate
re-exports through import *, 25 unused unpacked variables, 7 bare except:.
Worth keeping separate from a whitespace diff.

Runs `ruff format` over the whole repo: 41 of 46 files. The five that were
already formatted are the ones somebody had run a formatter over before.

Settings are pinned in pyproject.toml rather than left to ruff's defaults, so
that a change upstream is a deliberate edit here and not a surprise repo-wide
reformat. line-length 88 matches the already-formatted files.

skip-magic-trailing-comma is on. The trailing commas in this tree come from a
habit of writing `[8, ]`, not from a wish to keep those calls exploded; without
it, `smoothness_kernel([params[i], ], df[i])` becomes eight lines.

Markdown is excluded. Ruff formats the python blocks inside it, which in the
README splits a one-line call across three because a trailing comment pushes it
past the limit.

ruff is pinned to 0.16.x, since it is now a gate and a formatting change in a
new release would turn that gate red on a tree nobody touched.

This changes no behaviour. 36 of 44 files parse to a byte-identical AST; the
other 8 have identical structure and differ only in whitespace inside
docstrings. The suite is 69 passed either way, and `ruff check` finds the same
243 lint issues before and after, so the formatter neither fixed nor introduced
any.
@huangziwei
huangziwei merged commit 7701270 into master Aug 18, 2026
4 checks passed
@huangziwei
huangziwei deleted the ruff-format-repo branch August 18, 2026 10:00
@huangziwei huangziwei mentioned this pull request Aug 18, 2026
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