Skip to content

Adopt ruff format and enforce it in CI (#78) - #111

Merged
mpalermiti merged 4 commits into
mpalermiti:mainfrom
neilbrencode:fix/78-adopt-ruff-format
Oct 5, 2026
Merged

mpalermiti merged 4 commits into
mpalermiti:mainfrom
neilbrencode:fix/78-adopt-ruff-format

Conversation

@neilbrencode

Copy link
Copy Markdown
Contributor

Closes #78.

ruff format was documented in CLAUDE.md and the README, and nothing enforced it. Following it rewrote a large part of the tree and then failed ruff check. As you asked on #78, this adopts the formatter, leaves ruff check green by changing code rather than config, and gates both in CI. No contributor PR is open, so nothing has to rebase through it.

Commits, by shape

Commit What How to review it
style: ruff format src/ tests/ scripts/ Formatter output only: 49 files. Run uv run ruff format src/ tests/ scripts/ on the parent and diff. The result is empty.
style: name the To Do task mock once… Fixes the 5 E501s the format creates. One file, +14/−5.
ci: fail the build when a file is not ruff-formatted ruff format --check beside ruff check in ci.yml and publish.yml, plus docs. Small.
build: align and bound both ruff requirements ruff>=0.15.10,<0.17 in the dev extra and the dependency group. Small. Separable, see below.

The first commit deliberately fails ruff check on its own (the 5 E501s). That keeps it purely mechanical, as you asked; the second commit makes it green.

The format commit changes nothing a program can see

The formatter has moved on since #78 was filed. On today's main (f54a5a6, ruff 0.16.7 from uv.lock) it touches 48 files under src/ and tests/, up from 36, and 49 with scripts/.

Checked against its parent:

  • Syntax trees. Every changed file under src/ and scripts/ parses to an identical AST. Two test files differ only in a docstring that opens with a ": ruff inserts a space after the opening quotes (test_calendar_write.py, test_validation.py).
  • Tests. Same collected test ids, and the same result for every test: 1284 passed, 5 skipped.
  • What a client receives. tools/list, prompts/list and the server instructions are byte-identical (68 tools).
  • Comments. The formatter only re-aligned inline comments. No comment moved off the line it explains.

E501: a helper, not a wrap

All five long lines are the same mock chain in test_write_payloads_reach_the_wire.py:

client.me.todo.lists.by_todo_task_list_id.return_value.tasks.by_todo_task_id.return_value

It was already parenthesised, and the formatter joined it onto one line anyway, because an attribute chain has no call to break at. So wrapping it again doesn't stick. It is now named once as _todo_task_request(client), and each test keeps its own suffix (.patch, .checklist_items.post, …). There is no line-length change and no noqa.

That is a small refactor of a guard file, so I mutated each of the five suffixes in turn. Each mutation fails exactly the test that owns that site, and the other five To Do tests pass. Pointing the helper one level too high fails all five.

CI

  • ci.yml test job: ruff check src/ tests/ scripts/, then ruff format --check src/ tests/ scripts/, on every matrix entry, windows-latest included.
  • publish.yml "Tests and lint": the same two commands.
  • CLAUDE.md, the README's Development block and RELEASING.md §2 name the same commands. CHANGELOG has a ### Changed entry under [Unreleased].

To prove the gate can fail: rewriting one string literal in src/outlook_mcp/__init__.py with single quotes makes ruff format --check exit 1, naming that file. Restoring it exits 0.

Two additions beyond what you asked for, both separable

  1. scripts/ is covered too. preflight.py was lint-clean but unformatted. It is formatted in the first commit, and both CI commands now include scripts/. The formatted script still runs: read-only preflight against my mailbox, 15 of 15 probed endpoints OK. If you'd rather keep CI to src/ tests/, drop scripts/ from the two workflow lines.

  2. The ruff bounds, which The documented ruff format has never been run on this tree: 36 files / 991 lines, and it then breaks ruff check #78 listed as secondary. The dev extra asked for ruff>=0.4 and the dependency group for ruff>=0.15.10. With the new gate, that gap is a red build for a contributor who installs the extra with pip: 0.4.10, 0.6.9 and 0.8.6 each reformat 7 files of the formatted tree. Every release from 0.9.0 through 0.16.10 formats it identically.

    Both requirements become ruff>=0.15.10,<0.17, with a comment saying when to lift the cap. Ruff changes its stable style only in minor releases; a patch release changes it only to fix invalid syntax, a semantic change or a dropped comment (versioning policy). uv.lock changes only those two specifier lines and ruff stays at 0.16.7. uv lock --check passes on the new lock and fails on the old one. A lock-free uv pip install .[dev] resolves 0.16.10, which passes both commands. This is the last commit; drop it if you'd rather handle the bounds separately.

One question for you: blame

The issue suggested .git-blame-ignore-revs. I haven't added it, because it depends on how this merges:

  • Squash-merged (the usual here): the format commit's SHA never reaches main. The squash commit also carries the helper, CI and bounds changes, so ignoring it would hide their blame too.
  • Rebase-merged: the four commits keep their shape. A one-line follow-up can then name the format commit's SHA on main. The cost is one commit on main that fails ruff check on its own.

Either is fine with me. The ignore file can be a follow-up once the SHA exists.

Verification

At the head of this branch, on Windows 11 with Python 3.12 (CRLF checkout, the same as the windows-latest runner):

Job ruff check ruff format --check pytest
test (ubuntu-latest, 3.10–3.13) All checks passed 105 files already formatted 1289 passed
test (windows-latest, 3.12) All checks passed 105 files already formatted 1284 passed, 5 skipped
fresh-install — — green

Not run: publish.yml can't run without a release. Its two new lines are the same commands ci.yml runs.

This touches .github/workflows/, so it needs the workflow token scope to merge, or a merge from the UI as with #79, #81 and #105.

🤖 Generated with Claude Code

neilbrencode and others added 4 commits October 4, 2026 19:08
The output of `uv run ruff format src/ tests/ scripts/` (ruff 0.16.7, the
version uv.lock pins) and nothing else: 49 files. Reproduce by running the
same command on the parent; the diff is empty.

This commit alone fails `ruff check` with five E501s in
tests/test_write_payloads_reach_the_wire.py, where the formatter joins a
parenthesised mock chain onto one line. The next commit fixes them; the split
keeps this one purely mechanical (mpalermiti#78).

Checked against the parent: identical collected test ids, identical
per-test results (1284 passed, 5 skipped), and a byte-identical
tools/list, prompts/list and server instructions as a client receives them.

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

The previous commit's formatter run joined five parenthesised copies of
`client.me.todo.lists.by_todo_task_list_id.return_value.tasks
.by_todo_task_id.return_value` onto single lines of 111-154 characters,
which E501 rejects. The chain has no call to break at, so it cannot be
wrapped back; it is named once as `_todo_task_request(client)` and each
test keeps its own suffix (`.patch`, `.checklist_items.post`, ...).

A small refactor rather than a literal wrap, and still no `line-length`
change and no `noqa` (mpalermiti#78). Each suffix was mutated in turn: every
mutation fails exactly the test that owns that site and no other.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
`ruff format` was a documented command that nothing enforced, which is how
49 of 105 files drifted from it (mpalermiti#78). Both workflows now run
`uv run ruff format --check src/ tests/ scripts/` beside `ruff check`:
the `test` job in ci.yml on every matrix entry, windows-latest included,
and the "Tests and lint" step in publish.yml.

`ruff check` also covers `scripts/` now. preflight.py was already
lint-clean and was formatted in the first commit of this series, so the
two commands cover the same paths.

CLAUDE.md, the README's Development block and RELEASING.md section 2 name the
same commands and paths. CHANGELOG: a Changed entry under [Unreleased].

Verified locally: both commands exit 0 on this tree; turning one string
literal in src/outlook_mcp/__init__.py to single quotes makes
`ruff format --check` exit 1 naming that file.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The dev extra asked for `ruff>=0.4` and the dependency group for
`ruff>=0.15.10`. uv.lock hid the gap from anyone entering through
`uv sync`, but `pip install outlook-graph-mcp[dev]` could resolve a ruff
whose formatter disagrees with this tree: 0.4.10, 0.6.9 and 0.8.6 each
reformat 7 files of it. Now that CI fails on any unformatted file, that
is a red build for a contributor who followed the instructions (mpalermiti#78).

Both become `ruff>=0.15.10,<0.17`. Measured on this tree: 0.9.0 through
0.16.10 all format it identically. Ruff changes its stable style only in
minor releases (a patch release only to fix invalid syntax, a semantic
change or a dropped comment), so the cap is lifted once the next minor
leaves `ruff format --check` clean, as the comment says.

uv.lock: only the two specifier lines change; ruff stays at 0.16.7.
`uv lock --check` passes on it, and fails on the old lock. A lock-free
`uv pip install .[dev]` resolves ruff 0.16.10, which passes both
`ruff format --check` and `ruff check` on this tree.

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

Copy link
Copy Markdown
Contributor Author

@mpalermiti Ready for a review while there are no other open PRs

@neilbrencode

Copy link
Copy Markdown
Contributor Author

The red CI on this PR is GitHub's runners, not the change. Run 37366942798 has six failed jobs, and none of them ran a step. Each failed with "The job was not acquired by Runner of type hosted even after multiple attempts" after about 15 minutes of waiting. The two jobs that did get a runner passed: test (ubuntu-latest, 3.10) and mcp-publisher-pin. GitHub's status page has an open "Incident with Actions" that began at 19:11 UTC today.

The same commit, ec75998, passed every job on my fork in run 37346928408. That includes ruff format --check on all five test entries, windows-latest among them. Re-running the failed jobs once the incident clears should be enough. I can't trigger that from the fork.

- Claude Code

@mpalermiti
mpalermiti merged commit d31318a into mpalermiti:main Oct 5, 2026
17 of 24 checks passed
@mpalermiti

Copy link
Copy Markdown
Owner

Thanks, Neil — merged as a rebase so the format commit kept its shape. What I checked before merging:

  • Re-ran ruff format src/ tests/ scripts/ (0.16.7, from the lock) on f54a5a6: the result is byte-identical to 17df9c5.
  • Syntax trees: 47 of the 49 changed files are identical; the other two are the docstring space you named.
  • At ec75998, offline with HOME and the config dir redirected: ruff check clean, 105 files formatted, 1289 passed, uv lock --check clean.
  • _todo_task_request: pointing it one level too high failed all five To Do wire tests; reading .post instead of .patch failed only the update test.
  • CI on ec75998 needed two re-runs of the jobs the Actions incident never started; all green on the third attempt.

On the blame question: the format commit is fd449e4 on main, and #112 adds .git-blame-ignore-revs naming it. Nothing was changed on your branch.

Generated with Claude Code

mpalermiti added a commit that referenced this pull request Oct 5, 2026
#111 was rebase-merged so its formatter-only commit (fd449e4) reached
main on its own, as the blame question in #111 anticipated. Naming it in
.git-blame-ignore-revs, which GitHub's blame view reads automatically,
gives the 1,300 reformatted lines their real history back: across src/,
the lines blamed on the format commit drop from 170 to 3. The file says
how to enable it for local `git blame`.

Co-authored-by: Michael Palermiti <253352132+mpalermiti@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
@neilbrencode
neilbrencode deleted the fix/78-adopt-ruff-format branch October 5, 2026 22:28
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.

The documented ruff format has never been run on this tree: 36 files / 991 lines, and it then breaks ruff check

2 participants