Skip to content

Commit 5a48589

Browse files
authored
docs: Enable Ruff formatting of Python code blocks in Markdown (#982)
### What & why Ruff 0.16 formats Python code blocks embedded in Markdown files, and does so by default. In this repo the feature was inert because `[tool.ruff] include` was an allowlist of `*.py` globs, so no Markdown file ever reached the formatter. Adding `**/*.md` and `**/*.mdx` turns it on, which means docs snippets are now held to the same formatting standard as the rest of the codebase instead of drifting by hand. MDX needs the explicit `extension = { mdx = "markdown" }` mapping - without it Ruff would try to parse `.mdx` as Python and fail. Most of the Python snippets in `docs/` live in `.mdx`, so the mapping is what makes this useful here. No changes to the `lint` / `format` Poe tasks are needed. `lint` already runs `ruff format --check` and `format` already runs `ruff format`, so both pick Markdown up automatically. Note that `ruff check` (lint rules) does not support Markdown yet, so only formatting is enforced there. ### Notes - Code blocks under `docs/` are formatted to 90 columns, not 120, because of the existing `docs/pyproject.toml` override that keeps doc snippets free of a horizontal scrollbar. That is why one line in the upgrading guide got wrapped. - The second commit collapses the `include` allowlist to a single `**/*.py` glob. This is a pure simplification: no tracked `.py` file lives outside the previously listed directories, and Ruff processes exactly the same 189 files before and after. *✍️ Drafted by Claude Code*
1 parent 784006e commit 5a48589

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

docs/04_upgrading/upgrading_to_v3.mdx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ client.key_value_store('my-store').set_record('my-key', {'data': 1}, 'applicatio
8181
client.run('my-run').charge('my-event', 5, 'my-idempotency-key')
8282

8383
# After
84-
client.key_value_store('my-store').set_record('my-key', {'data': 1}, content_type='application/json')
84+
client.key_value_store('my-store').set_record(
85+
'my-key', {'data': 1}, content_type='application/json'
86+
)
8587
client.run('my-run').charge('my-event', count=5, idempotency_key='my-idempotency-key')
8688
```
8789

@@ -97,10 +99,10 @@ Generated enum-like types are now [`Literal`](https://docs.python.org/3/library/
9799

98100
```python
99101
# Before
100-
event_types=[WebhookEventType.ACTOR_RUN_SUCCEEDED]
102+
event_types = [WebhookEventType.ACTOR_RUN_SUCCEEDED]
101103

102104
# After
103-
event_types=['ACTOR.RUN.SUCCEEDED']
105+
event_types = ['ACTOR.RUN.SUCCEEDED']
104106
```
105107

106108
Affected types: `ActorJobStatus`, `ActorPermissionLevel`, `ErrorType`, `GeneralAccess`, `HttpMethod`, `RunOrigin`, `SourceCodeFileFormat`, `StorageOwnership`, `VersionSourceType`, `WebhookDispatchStatus`, `WebhookEventType`. For more on the generated types and how they fit into the typed client surface, see [Typed models](/api/client/python/docs/concepts/typed-models).

pyproject.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,16 @@ source-include = ["CHANGELOG.md", "CONTRIBUTING.md"]
7474
[tool.ruff]
7575
line-length = 120
7676
include = [
77-
"src/**/*.py",
78-
"tests/**/*.py",
79-
"scripts/**/*.py",
80-
"docs/**/*.py",
81-
"website/**/*.py",
77+
"**/*.py",
78+
# Ruff formats Python code blocks embedded in Markdown files.
79+
"**/*.md",
80+
"**/*.mdx",
8281
]
8382
exclude = [
8483
"website/versioned_docs/**",
8584
]
85+
# MDX is Markdown; without this mapping Ruff would try to parse `.mdx` files as Python.
86+
extension = { mdx = "markdown" }
8687

8788
[tool.ruff.lint]
8889
select = ["ALL"]

0 commit comments

Comments
 (0)