Skip to content

Commit 12da800

Browse files
committed
Add ai_notes/docs_todos.md for literalinclude idea
Notes on using sphinx `literalinclude` to auto-sync `docs/README.rst` code examples with actual source files instead of manual duplication. (this patch was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code
1 parent 5ac7394 commit 12da800

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

.claude/ai_notes/docs_todos.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Docs TODOs
2+
3+
## Auto-sync README code examples with source
4+
5+
The `docs/README.rst` has inline code blocks that
6+
duplicate actual example files (e.g.
7+
`examples/infected_asyncio_echo_server.py`). Every time
8+
the public API changes we have to manually sync both.
9+
10+
Sphinx's `literalinclude` directive can pull code directly
11+
from source files:
12+
13+
```rst
14+
.. literalinclude:: ../examples/infected_asyncio_echo_server.py
15+
:language: python
16+
:caption: examples/infected_asyncio_echo_server.py
17+
```
18+
19+
Or to include only a specific function/section:
20+
21+
```rst
22+
.. literalinclude:: ../examples/infected_asyncio_echo_server.py
23+
:language: python
24+
:pyobject: aio_echo_server
25+
```
26+
27+
This way the docs always reflect the actual code without
28+
manual syncing.
29+
30+
### Considerations
31+
- `README.rst` is also rendered on GitHub/PyPI which do
32+
NOT support `literalinclude` - so we'd need a build
33+
step or a separate `_sphinx_readme.rst` (which already
34+
exists at `docs/github_readme/_sphinx_readme.rst`).
35+
- Could use a pre-commit hook or CI step to extract code
36+
from examples into the README for GitHub rendering.
37+
- Another option: `sphinx-autodoc` style approach where
38+
docstrings from the actual module are pulled in.

0 commit comments

Comments
 (0)