Skip to content

feat: use ruff to format docs code instead of blacken-docs - #833

Merged
henryiii merged 5 commits into
mainfrom
ruff-016-markdown-docs
Jul 24, 2026
Merged

feat: use ruff to format docs code instead of blacken-docs#833
henryiii merged 5 commits into
mainfrom
ruff-016-markdown-docs

Conversation

@henryiii

@henryiii henryiii commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

I think "markdown" will be added to the hook, in which case this simplifies. See astral-sh/ruff-pre-commit#159.

Close #343.

🤖 AI text below 🤖

Ruff 0.16 can format Python code blocks in Markdown, a stable blacken-docs replacement, so one tool now covers both code and docs.

  • Template & this repo: drop the blacken-docs hook, bump ruff-pre-commit to v0.16.0, and add markdown to the ruff-format hook's types_or (the hook filters files, so Markdown must be listed).
  • PC111 retitled to "Formats code in docs"; it now passes with either blacken-docs or a ruff-format hook that has markdown in types_or. Still flags the old asottile/blacken-docs URL.
  • Guide: recommend the ruff-format approach first, keeping blacken-docs for Black users or reStructuredText (which ruff doesn't format); bumped ruff revs to v0.16.0.
  • Enabling this on our own docs reformatted one code block in docs/principles/design.md (a trailing comma).

Ruff 0.16 also expands the default rule set, but the guide already recommends an explicit select, so that change doesn't affect projects following it.


📚 Documentation preview 📚: https://scientific-python-cookie--833.org.readthedocs.build/

@henryiii
henryiii force-pushed the ruff-016-markdown-docs branch from cc2937c to ebe1a42 Compare July 24, 2026 05:12
henryiii added 2 commits July 24, 2026 01:18
Ruff 0.16 formats Python code blocks in Markdown, so a single tool covers
both code and docs. Drop the blacken-docs hook, bump ruff-pre-commit to
v0.16.0, and add markdown to the ruff-format hook's types_or.

PC111 now passes with either blacken-docs or a ruff-format hook that lists
markdown in types_or.

Assisted-by: ClaudeCode:claude-opus-4.8
Assisted-by: ClaudeCode:claude-opus-4.8
@henryiii
henryiii force-pushed the ruff-016-markdown-docs branch from ebe1a42 to 99b32d8 Compare July 24, 2026 05:18
@henryiii henryiii closed this Jul 24, 2026
@henryiii henryiii reopened this Jul 24, 2026
henryiii added 3 commits July 24, 2026 15:23
Ruff's pre-commit hook will format Markdown by default at some point.
Pass PC111 unless the ruff-format hook filters Markdown out, instead of
requiring a literal `markdown` entry.

Assisted-by: ClaudeCode:claude-opus-5
Assisted-by: ClaudeCode:claude-opus-5
Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
@henryiii
henryiii merged commit 60770f4 into main Jul 24, 2026
33 checks passed
@henryiii
henryiii deleted the ruff-016-markdown-docs branch July 24, 2026 22:32
Alexboiboi added a commit to magpylib/magpylib that referenced this pull request Aug 26, 2026
* Update from scientific-python/cookie template `2026.08.14`

Ran `copier update` from `2026.04.04`. Notable upstream changes:

- blacken-docs is gone; ruff-format now handles markdown, jupyter and
  pyproject code blocks instead (scientific-python/cookie#833).
- The ruff `extend-select` list drops BLE, DTZ, FA, FLY, I, PIE and YTT,
  which Ruff 0.16 selects by default (scientific-python/cookie#843).
- zizmor joins pre-commit, with `.github/zizmor.yml` allowing ref pins.
- Workflows gain a top level `permissions: {}` with per-job grants, and
  `persist-credentials: false` on checkout.
- `actions/attest-build-provenance` -> `actions/attest`, which generates
  SLSA build provenance when handed no predicate inputs.
- Dependabot gets a seven day cooldown.

Conflicts were resolved in favour of ours wherever the project has
deliberately diverged: the Read the Docs `commands:` block stays (it needs
libgl1-mesa-dev and sphinx-apidoc, so only the interpreter bump to 3.14 was
taken), as do the disabled mypy hook (rev synced to v2.3.0 for whenever it
is enabled), the pyvista headless display and pypy OpenBLAS steps, the note
explaining the hynek pin, and our test matrix.

The checks job also sheds a duplicate `astral-sh/setup-uv` invocation and an
`allow-prereleases` input that was being handed to setup-uv, which has no
such input. Both arrived in #954. Python now comes from setup-python again,
as the template intends.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* Reformat docs code blocks with ruff-format

Falls out of swapping blacken-docs for ruff-format in the template update:
an implicit f-string concatenation collapses onto one line, `{i+1}` gains
spaces around the operator, and two blank lines after a `for` go away.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* Pin the CI matrix interpreter for uv

Now that setup-python provides the interpreter rather than setup-uv, `uv
sync` is no longer handed one explicitly and discovers it off PATH. Setting
UV_PYTHON keeps the matrix honest: a discovery mismatch would fail open and
test the same version twice under two different job names.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <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.

Add support for Ruff's docstring-code-format

1 participant