docs: render docstring examples as code in the API reference (#1128) - #1129
Merged
Merged
Conversation
griffe's Google-style parser only recognises the plural "Examples:" section title. Eleven docstrings used "Example:", which fell through to a generic admonition rendered as markdown, so the ">>>" prompts became three nested blockquotes (the vertical bars in the issue screenshot) and the code lost its highlighting. Rename them all to "Examples:"; the two prose examples (Batch.load, BaseLoader.get_raw_units) switch from RST "::" literal blocks to fenced python blocks so they highlight too. The list_templates return description now indents its continuation lines so griffe reads one item instead of four. Add tests/test_docstring_sections.py (essential): an ast scan of src/cellpy docstrings that fails with file:line on any new singular "Example:" title. Closes #1128 Co-authored-by: Jan Petter Maehlen <jepe@ife.no>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1128
Root cause
griffe's Google-style parser (
griffelib 2.1.0,_section_kind) only recognises the pluralExamples:section title. Eleven docstrings insrc/cellpyusedExample:, which falls through to a generic admonition whose body mkdocstrings renders as markdown. A line starting with>>>is three nested markdown blockquotes — the three vertical bars in the issue screenshot — and the code becomes plain paragraph text with the prompts eaten. A localzensical buildreproduced it exactly (<details class="example"><blockquote><blockquote><blockquote>…).The same screenshot shows a second format bug: the
list_templatesReturns:description wrapped at the same indent as its first line, so griffe split it into fourdictitems.Fix (docstring level, as the issue preferred)
Example:→Examples:(cli_api.py,ica.py×3,collect/ica.py,collect/dva.py,readers/cellreader.py×2,parameters/internal_settings.py,batch/facade.py,readers/instruments/base.py).Batch.load,BaseLoader.get_raw_units) switch from RST::literal blocks to fenced```pythonso they highlight underExamples:.list_templatesReturns:continuation lines indented → one item.tests/test_docstring_sections.py(essential, stdlibast, <1 s): fails withfile:lineon any bareExample:title insrc/cellpy. Onmasterit lists all 11 offenders; here it passes. Registry row added.Before / after
Before (from the issue):
Before: nested blockquotes, plain text, four dict return items
After (rebuilt locally,
site/api/cellpy/):After: single Returns item and highlighted pycon Examples block
How to test
uv run pytest tests/test_docstring_sections.py— passes;git stash -- srcand rerun to see it fail on the 11 old titles.uv run --group docs zensical build --clean→No issues found;rg -c '<details class="example"' site/api→ no hits (was 4 API pages).uv run .issueflows/00-tools/check_docs_relative_links.py→ all resolve.MPLBACKEND=Agg uv run pytest -m essential→ 982 passed, 74 skipped; the 2test_filefinder.py::test_find_by_project_*failures are the same VM-only ones that also fail on a stashedorigin/masterhere while master CI is green.To show artifacts inline, enable in settings.