Skip to content

Unify doctest replay extraction and fix installed-package bootstrap#13

Merged
chrizzFTD merged 8 commits into
cursor/autodoc-doctest-repl-3c18from
cursor/autodoc-unified-doctest-replay-25c4
Jun 29, 2026
Merged

Unify doctest replay extraction and fix installed-package bootstrap#13
chrizzFTD merged 8 commits into
cursor/autodoc-doctest-repl-3c18from
cursor/autodoc-unified-doctest-replay-25c4

Conversation

@chrizzFTD

@chrizzFTD chrizzFTD commented Jun 28, 2026

Copy link
Copy Markdown
Owner

Summary

Phase 2 follow-up for autodoc REPL integration, addressing the two bugs found when building the naming docs.

1. Unified doctest_to_replay_source()

Single conversion function for both autodoc doctest blocks and .. py-repl:: directive bodies:

  • Uses doctest.DocTestParser only — strips expected output, splits examples, joins with blank lines
  • No fallback path; non-doctest input returns empty string
  • Removed strip_doctest_prompts() and extract_doctest_source()

2. Installed-package bootstrap via packages=

For modules outside the Sphinx source tree, autodoc REPLs emit packages="<top-level module>" (micropip) instead of exec'ing inspect.getsource(). In-tree demo modules still use silent :src:.

Tests

pytest -v   # 20 passed

Follow-up

After merge, naming can drop the temporary pyrepl_autodoc_fix.py monkey-patch (PR chrizzFTD/naming#31).

Open in Web Open in Cursor 

Add doctest_to_replay_source() as the single conversion path for both
autodoc doctest blocks and py-repl directive bodies. DocTestParser strips
expected output and joins separate examples with blank lines so multiline
class definitions remain valid Python.

For installed modules outside the Sphinx source tree, autodoc REPLs now
emit packages= via micropip instead of exec'ing module source (which fails
for packages with relative imports). In-tree modules still use silent :src:.

Includes naming-shaped doctest tests and an installed-package integration
test with relative imports in __init__.py.

Co-authored-by: chrizzftd <chrizzFTD@users.noreply.github.com>
@read-the-docs-community

read-the-docs-community Bot commented Jun 28, 2026

Copy link
Copy Markdown

Documentation build overview

📚 sphinx-pyrepl-web | 🛠️ Build #33352549 | 📁 Comparing c6902e1 against latest (ef2ee2b)

  🔍 Preview build  

3 files changed
± example.html
± genindex.html
± index.html

Remove strip_doctest_prompts fallback and extract_doctest_source alias.
DocTestParser is the sole conversion path for both autodoc blocks and
py-repl directive bodies.

Co-authored-by: chrizzftd <chrizzFTD@users.noreply.github.com>
@chrizzFTD

Copy link
Copy Markdown
Owner Author

@cursoragent review

@cursor

cursor Bot commented Jun 29, 2026

Copy link
Copy Markdown

PR Review: Unify doctest replay extraction and fix installed-package bootstrap (#13)

Verdict: Approve — ready to merge into cursor/autodoc-doctest-repl-3c18

This PR cleanly addresses both naming bugs with a smaller, more coherent surface area than the original monkey-patch approach. RTD preview builds successfully.


What works well

Unified extractiondoctest_to_replay_source() is a good simplification. One 12-line function, DocTestParser only, shared by autodoc and the directive. Removing strip_doctest_prompts() and the fallback eliminates the divergence that caused the naming Name syntax error.

Blank-line joining\n\n.join(examples) is the correct fix for multiline class blocks. The naming-shaped unit test and integration tests confirm it.

Installed-package bootstrap — Replacing inspect.getsource() with packages=module_name.split(".")[0] is the right call. It aligns autodoc REPLs with Overview's working :packages: naming pattern and avoids exec'ing package source with relative imports. The new installed_pkg integration test (relative import in __init__.py) is exactly the regression we needed.

Net reduction — ~53 lines removed overall despite adding tests. Matches the stated preference for minimal, debt-free code.

Tests — 20/20 pass locally. Coverage spans unit (extraction), integration (autodoc scope, in-tree :src:, out-of-tree packages=), and existing build/replay tests still pass through the unified path.


Minor cleanup (optional, can follow up)

Item Notes
Dead bootstrap_content path _resolve_autodoc_bootstrap never returns bootstrap content anymore, but register_autodoc_repl still supports writing -bootstrap.py files. Harmless but could be removed in a small follow-up to simplify the API.
module_name.split(".")[0] heuristic Fine for naming, repl_test_demo, etc. Fails when PyPI name ≠ import top-level (e.g. yamlPyYAML). Worth a one-line README caveat; a pyrepl_autodoc_packages override can wait.
Silent bootstrap failure Import/OSError still returns (None, None, None) with no Sphinx warning. User sees NameError at runtime. Low priority; same as before for the failure case.
Non-doctest directive bodies Plain Python in .. py-repl:: (no >>>) now produces an empty replay script. Intentional and correct given the DocTestParser-only decision; worth noting in docs if not already implied.

None of these block merge.


Confirmed against naming issues

Original bug Fixed by
Missing blank lines → SyntaxError after class body doctest_to_replay_source() joins examples with \n\n
Bootstrap exec of __init__.py with relative imports packages="naming" via micropip
Overview worked, autodoc didn't Both paths now consistent for installed packages

After this merges into the autodoc branch and naming drops pyrepl_autodoc_fix.py, the workaround in naming#31 can be removed.


Summary

Area Rating
Design Strong — single conversion path, removes broken bootstrap strategy
Correctness Good — addresses both root causes with targeted tests
Minimalism Strong — deletes more code than it adds
Docs Adequate — README/example.rst updated for in-tree vs installed bootstrap
CI / RTD Green — preview build available

Recommendation: Merge into cursor/autodoc-doctest-repl-3c18, then proceed with naming validation (Phase 3). Optional follow-up PR to drop the unused bootstrap_content machinery.

Open in Web Open in Cursor 

cursoragent and others added 3 commits June 29, 2026 09:03
Drop generated -bootstrap.py support from register_autodoc_repl and
simplify _resolve_autodoc_bootstrap to return (src, packages) only.

Co-authored-by: chrizzftd <chrizzFTD@users.noreply.github.com>
Autodoc doctest conversion is now disabled unless clients set
pyrepl_doctest_blocks to "autodoc" or "all". Extension docs and
autodoc tests opt in explicitly.

Co-authored-by: chrizzftd <chrizzFTD@users.noreply.github.com>
Signed-off-by: Christian López Barrón <chris.gfz@gmail.com>
@chrizzFTD
chrizzFTD marked this pull request as ready for review June 29, 2026 09:35
Signed-off-by: Christian López Barrón <chris.gfz@gmail.com>
Signed-off-by: Christian López Barrón <chris.gfz@gmail.com>
Signed-off-by: Christian López Barrón <chris.gfz@gmail.com>
@chrizzFTD
chrizzFTD merged commit 7deb201 into cursor/autodoc-doctest-repl-3c18 Jun 29, 2026
4 checks passed
@chrizzFTD
chrizzFTD deleted the cursor/autodoc-unified-doctest-replay-25c4 branch June 29, 2026 09:46
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.

2 participants