Skip to content

docs: ruff-format & compile-check examples; Tonnikala syntax; package guidance - #8

Merged
ztane merged 3 commits into
masterfrom
docs-ruff-format-examples
Jun 19, 2026
Merged

docs: ruff-format & compile-check examples; Tonnikala syntax; package guidance#8
ztane merged 3 commits into
masterfrom
docs-ruff-format-examples

Conversation

@ztane

@ztane ztane commented Jun 18, 2026

Copy link
Copy Markdown
Member

Documentation correctness & tooling

Three related fixes to the narrative/tutorial docs, plus tooling to keep them honest.

1. ruff-format every example (f9e703e)

All 196 code-block:: python examples are now formatted exactly like the source tree. Adds tools/format_doc_examples.py — a self-contained uv script that extracts each example, runs it through ruff format (pinned ruff==0.4.4, matching the ruff-format pre-commit hook), and reindents it back into the RST. Supports --check; wired in as a pre-commit hook over docs/**.rst. 113 examples reformatted.

2. Correct template syntax, datetimes, project layout (8eb4452)

  • Tonnikala, not Chameleon. Replaced the Chameleon |n no-escape filter with Tonnikala's $literal(...), renamed .pt/.html renderer targets to .tk, dropped the "Chameleon template" labels, and switched attribute/call chains (CSRF token, static_url) to bare $ interpolation to match templating.rst.
  • Timezone-aware datetimes. Replaced datetime.utcnow with datetime.now(timezone.utc) across the tutorials (and added a missing datetime import the JSON error-adapter example needed).
  • Single file vs package. The quickstart now says a single file is fine for small apps, but real applications should be organised as a package, with a recommended layout.

3. Compile-check every example (05137fe)

Adds tools/doc_examples.py (stdlib RST extractor, shared with the formatter) and tests/test_doc_examples.py, which compile()s all 196 examples so syntactically broken or tooling-mangled snippets fail CI. Also a compile-doc-examples pre-commit hook. Snippets can opt out with .. doc-example: no-compile.

Verification

  • rstcheck clean across docs/
  • tests/test_doc_examples.py: 197 passed
  • both new pre-commit hooks pass
  • ruff check / ruff format --check clean (pinned 0.4.4)

https://claude.ai/code/session_011KKd5BtHMWfrF9WRRMwg7F

ztane added 3 commits June 18, 2026 16:00
Adds tools/format_doc_examples.py, a self-contained uv script that extracts
the Python code-block examples from the reStructuredText docs and runs them
through ruff format (pinned ruff==0.4.4, matching the ruff-format pre-commit
hook), so documentation snippets follow the same style as the rest of the
source tree. Supports --check for CI and skips intentionally partial snippets.

Wires it into .pre-commit-config.yaml as a local hook that checks docs/**.rst,
and reformats all 113 drifting examples across the narrative and tutorial docs.

Claude-Session: https://claude.ai/code/session_011KKd5BtHMWfrF9WRRMwg7F
- Templates: use Tonnikala syntax throughout instead of Chameleon. Replace the
  Chameleon ``|n`` no-escape filter with Tonnikala's $literal(...), rename
  ``.pt``/``.html`` renderer targets to ``.tk``, drop the "Chameleon template"
  labels, and use bare $ interpolation for attribute/call chains (csrf token,
  static_url) to match templating.rst.
- Tutorials: replace datetime.utcnow with timezone-aware
  datetime.now(timezone.utc) (and add the missing datetime import in the JSON
  error-adapter example).
- Quickstart: note that a single file is fine for small apps but real
  applications should be organised as a package, with a recommended layout.

Claude-Session: https://claude.ai/code/session_011KKd5BtHMWfrF9WRRMwg7F
Adds tools/doc_examples.py, a stdlib RST code-block extractor shared by the
formatter and a new tests/test_doc_examples.py that compile()s all 196 Python
examples (guarding against syntactically broken or tooling-mangled snippets).
Refactors format_doc_examples.py to reuse the shared parser, and adds a
compile-doc-examples pre-commit hook alongside the pytest gate. Snippets can
opt out with a '.. doc-example: no-compile' comment.

Claude-Session: https://claude.ai/code/session_011KKd5BtHMWfrF9WRRMwg7F
@ztane

ztane commented Jun 19, 2026

Copy link
Copy Markdown
Member Author

Bypassing review as it is essentially documentation formatting.

@ztane
ztane merged commit 385885f into master Jun 19, 2026
10 checks passed
@ztane
ztane deleted the docs-ruff-format-examples branch June 19, 2026 06:25
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