Skip to content

Generate API docs with sphinx-autodoc2 for Markdown support - #784

Draft
eb8680 wants to merge 1 commit into
masterfrom
worktree-autodoc2-migration
Draft

Generate API docs with sphinx-autodoc2 for Markdown support#784
eb8680 wants to merge 1 commit into
masterfrom
worktree-autodoc2-migration

Conversation

@eb8680

@eb8680 eb8680 commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Resolves #774

This seems to be the path of least resistance to resolving #774 according to the LLMs and the Myst and Sphinx documentation. sphinx.ext.autodoc has no built-in support for Markdown docstrings. Rewriting the offending harness docstrings as RST isn't ideal because RST in model-facing text doesn't play well with the renderer in handlers.llm.harness.observability.rich. Migrating the entire rest of the repo away from Sphinx to Markdown and MkDocs/Zensical would be nice in theory but also touch almost every file and break all open PRs.

`sphinx.ext.autodoc` imports the package and introspects live objects;
`sphinx-autodoc2` reads the source with `astroid` instead. Two things
motivate the switch.

The docstrings in `handlers.llm` are Markdown, and RST rendered them as
literal `##` and broken fence anchors. They are model-facing -- the
legibility framework and every `PromptInjectingInterpretation` inject
them into the system prompt verbatim, and `serialization` parses their
ATX headings to rebase heading levels -- so the renderer moves to the
docstrings rather than the other way round.
`autodoc2_docstring_parser_regexes` names the six that are Markdown;
the rest of the package stays reStructuredText.

The hand-written `.. autofunction::` overrides also go away. They
existed because `automodule :members:` skips names whose `__module__`
differs: the torch wrappers `functools.wraps` relabels as `torch.func`,
and the jax operations re-exported from `._handlers`. Static analysis
sees the `def` regardless, so all eleven torch functions render on their
own; jax needs an `__all__` to resolve its re-exports, since analysis
never follows imports.

Two configuration choices are less obvious than they look.
`autodoc2_render_plugin` stays `rst`: MyST pages would make MyST the
default parser for every docstring, and CommonMark reads a `>>>` prompt
as a blockquote, so `ops.syntax` alone turned 31 doctest blocks into 186
nested quotes. And `autodoc2_docstrings` is `direct`, not `all`, despite
the latter looking like the analogue of `autodoc_inherit_docstrings`:
the old `effectful.rst` never passed `:inherited-members:`, and `all`
repeats a base class's docstring on every subclass -- 40 copies of
`_DistributionTerm` across the numpyro wrappers, `Operation`'s doctests
onto two subclasses in `ops.syntax`, and stdlib boilerplate onto classes
whose base is a `dict` or an `ABC`.

The API reference is now a page per module under `apidocs/`, so
`effectful.rst` becomes a redirect and per-object anchors no longer
resolve. `sphinx_autodoc_typehints` is dropped because it only hooks
autodoc events, and `sphinxcontrib-bibtex` because nothing used it.

The docs jobs keep their unpinned interpreter. `sphinx-autodoc2` pins
`astroid<4`, so 3.14 looked like a risk, but building under 3.14.7 --
what `uv python install` resolves to -- gives an API tree byte-identical
to 3.13, the same 30 warnings and the same 36 `_modules` pages.

Static analysis does not see everything an import does. PEP 695 `type`
aliases (including `Expr`), definitions inside module-level `try:` or
`if TYPE_CHECKING:` blocks (`Encodable`), `@overload`-only members, and
six of the seven torch functorch wrappers' signatures are absent, and
per-module `:private-members:` is no longer expressible.
@eb8680
eb8680 force-pushed the worktree-autodoc2-migration branch from 084e7fa to cf7fd7d Compare September 5, 2026 01:30
@eb8680
eb8680 marked this pull request as draft September 5, 2026 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clean up documentation formatting in effectful.handlers.llm

1 participant