Repository navigation
fix(docs-gen): fence bare docstring examples and escape MDX braces (SAO-18112) - #320
Conversation
…s code (SAO-18112) Address Astra review on #320: - Examples with an RST `::` lead-in are routed through _sanitize_description so only the indented code is fenced; the prose and `::` marker are no longer swallowed into a python block (e.g. get_metric_aggregate). - Notes use _sanitize_description so `::` blocks in notes are fenced and their braces are not escaped. - Add regression tests for both shapes. Co-Authored-By: Claude <noreply@anthropic.com>
…AO-18112) The generator only fenced >>> doctest examples, so bare examples in SDK docstrings were emitted as brace-escaped prose on every regeneration. - Add _render_examples/_strip_doctest_prompts: every example is fenced as python, doctest prompts are stripped per line, pre-fenced examples pass through. Replaces the duplicated loops in write_function and write_class. - Render module-level examples in write_module (previously dropped). - Escape braces in notes so they cannot break MDX. - Skip inline code spans of any backtick width when escaping braces, so RST ``literals`` no longer show literal backslashes. - Add regression tests for bare, doctest, mixed and pre-fenced examples, multi-backtick spans, and module examples. Co-Authored-By: Claude <noreply@anthropic.com>
…s code (SAO-18112) Address Astra review on #320: - Examples with an RST `::` lead-in are routed through _sanitize_description so only the indented code is fenced; the prose and `::` marker are no longer swallowed into a python block (e.g. get_metric_aggregate). - Notes use _sanitize_description so `::` blocks in notes are fenced and their braces are not escaped. - Add regression tests for both shapes. Co-Authored-By: Claude <noreply@anthropic.com>
8495fac to
af76190
Compare
Examples that are plain Markdown bullet lists (for example generate_unique_name in utils/prompts.py) were fenced as python after the fence-everything change. Render bullet-only examples as prose through _sanitize_description so braces are still escaped. YAML-style `- key: value` lists stay fenced as code. Co-Authored-By: Claude <noreply@anthropic.com>
etserend
left a comment
There was a problem hiding this comment.
🤖 This review was generated by the Astra agent (claude-opus-5-5). It may contain mistakes.
Verdict: approve — Examples and notes now render correctly. Regenerated docs differ from main only in the intended fences and brace escapes. The earlier :: concern is fixed.
Addressed before this review
- RST
::lead-in examples (for exampleget_metric_aggregate) were fenced as Python together with their prose and the::marker. Fixed in af76190: these examples now go through_sanitize_description, andTestRstLiteralBlockExamplescovers them.
Follow-ups
Suggested follow-up work that could be tracked as Jira tickets:
scripts/create_docs.py:606-608: The::branch sends the example through_sanitize_description, and that path never calls_strip_doctest_prompts. An RST literal block that holds>>>lines would keep its prompts inside the fence. No docstring insrc/splunk_aohas this shape today. I searched for::lines followed by>>>within 3 lines and found none. Consider stripping the prompts inside the converted block, and add a test for it.src/splunk_ao/exceptions.py:101-102: This docstring is not raw, so\\"becomes\"in the rendered example. The result isb"{\\"detail\\": ...}", which is not valid Python. It is the only fenced example in the regenerated docs thatast.parserejects. Make the docstring raw, or simplify the literal.
…le (SAO-18112) Address the second Astra round on #320: - RST `::` examples now strip doctest prompts before conversion; _strip_doctest_prompts keeps indentation and leaves an indented bare `...` placeholder body untouched. - Simplify the NotFoundError docstring examples so the rendered code is valid Python (the non-raw `\\"` escapes rendered as `\\\\"`). Co-Authored-By: Claude <noreply@anthropic.com>
Both fixed in aeb14f2 (:: blocks now strip >>> prompts, and the NotFoundError examples are valid Python). |
Summary
Fixes SAO-18112. The reference-docs generator (
scripts/create_docs.py) only fenced>>>doctest examples. Bare examples in SDK docstrings were emitted as brace-escaped prose, so code rendered as plain text,#comments became headings, and braces showed as\{...\}on every regeneration (for example thedatasetreference page).Changes
_render_examples/_strip_doctest_prompts: every example is fenced as```python, doctest prompts are stripped on every line (not just the first), and examples that already contain a fence pass through unchanged. Replaces the duplicated loops inwrite_functionandwrite_class.::lead-in go through_sanitize_description, so only the indented code is fenced and the prose stays prose (found in Astra review:get_metric_aggregate)._sanitize_description, so::blocks in notes are fenced and their braces are not escaped.generate_unique_nameinutils/prompts.py) stay prose through_sanitize_descriptioninstead of being fenced as Python (found in the second Astra round). YAML-style- key: valuelists stay fenced as code.::examples strip>>>/...prompts before conversion (second Astra round)._strip_doctest_promptskeeps indentation and leaves an indented bare...placeholder body alone.NotFoundErrordocstring examples insrc/splunk_ao/exceptions.py; the non-raw\\"escapes rendered as invalid Python (b"{\\"detail\\": ...}"). Docstring-only change, same example meaning.write_module(previously dropped; no visible effect today because__init__modules are not emitted).``literals``no longer show literal backslashes.Validation
Generated reference docs from this branch (rebased on
origin/main) vs the docs repomain, 81 pages each:utils/prompts)@mdx-js/mdx)dataset(examples are code blocks, braces literal) andexperiment/get_metric_aggregate(prose outside the fence, no stray::).pytest tests/test_create_docs_helpers.py -n 0: 45 passed (23 new).ruff check --no-fix scripts tests/test_create_docs_helpers.py: 2 findings (RET504in_sanitize_description,I001in the test file), both present onmainand left untouched.Rendered result (Mintlify preview of agent-observability-docs#173)
Preview: https://agent-observability-docs-feat-update-docs-fix-sao-18112-fen.mintlify.site/sdk-api/python/reference/dataset
Confirmed by eye on the
datasetpage in a browser (not only by script):# commentline became a large heading.{"input": "What is machine learning?", "output": "Machine learning ..."}, with no\{/\}backslashes.add_rows,create,delete,extend,generate,get,get_content,get_version_content,get_versions,list,refresh,save), so no sections were lost.experiment>get_metric_aggregate: the sentence "Poll until a specific metric is computed, then assert" is plain text above the code block, the stray::is gone, and the code is a normal block.Known limitations (not in this PR)
publish-docs.yamlinstallsdocstring-parser>=0.17.0unpinned, so CI output can differ from a local run for reasons unrelated to this change (for examplecount (int, default 10)vscount (int)ondatasets). Pinning it is a separate follow-up.Code produced from an RST
::block starts with one blank line inside the fence. This comes from the existing_convert_rst_code_blocksand is locked in by existing tests.Doctest output lines can land inside python fences (for example
UnconfiguredProviderinprovider.py). The extraction logic is unchanged; worth a separate ticket.Optional CI hardening in
publish-docs.yaml(run the helper tests, pindocstring-parser) is a follow-up.