Normalize emitted asset paths for nested Sphinx pages#20
Conversation
Rewrite file-like paths in py-repl attributes to page-relative URLs using Sphinx get_target_uri and relative_uri. This fixes REPL asset loading on nested doc pages while preserving flat-layout behavior and compatibility with RTD-style path prefixes. Adds asset_href helpers, unit tests, a nested-page build fixture, and README documentation. Closes #19. Co-authored-by: chrizzftd <chrizzFTD@users.noreply.github.com>
Documentation build overview
|
Use app.builder in transforms and env._app.builder in PyRepl.run(), matching Sphinx internals. asset_href now takes a Builder directly. Co-authored-by: chrizzftd <chrizzFTD@users.noreply.github.com>
|
@cursoragent review |
PR Review: #20 — Normalize emitted asset paths for nested Sphinx pagesVerdict: Approve. This is a solid, well-scoped fix for #19. CI is green (latest run succeeded after the What works well1. Correct path strategy Using 2. Clean separation of concerns
That keeps metadata/copy logic simple and avoids double-rewriting. 3. Sensible file-like heuristic def asset_href(builder: Builder, docname: str, path: str) -> str:
"""Rewrite a file path for the HTML page that will emit it."""
if not _is_file_like_path(path):
return path
if builder.format != "html":
return path
return relative_uri(builder.get_target_uri(docname), path)PyPI names, absolute URLs, micropip specs ( 4. Good test coverage
5. CI fix is appropriate
Minor nits (non-blocking)
RTD previewThe Read the Docs preview shows changes to Issue #19 acceptance criteria
RecommendationMerge when ready. No required changes. Optional follow-ups (can be separate PRs):
Good work on pushing back against the |
Rename asset_href and asset_href_packages to _asset_href and _asset_href_packages so they are not mistaken for public extension API. Co-authored-by: chrizzftd <chrizzFTD@users.noreply.github.com>
5444564
into
cursor/autodoc-bootstrap-src-only-16b5


Summary
Fixes #19 by rewriting file-like paths in emitted
<py-repl>attributes to page-relative URLs at build time, so REPLs work on nested Sphinx pages (e.g.api/module.html) without breaking RTD-style path prefixes.This deliberately uses Sphinx's
get_target_uri()+relative_uri()rather than the issue's proposed/_static/…root-absolute paths, which would break docs hosted under version/language prefixes.Changes
asset_href()/asset_href_packages()helpers insphinx_pyrepl_web/__init__.pypackages,src, andreplay-srcinPyRepl.run()andmake_pyrepl_raw()register_autodoc_*()return values unchanged (canonical paths forcopy_asset_files())/, or ending in.whl/.py); PyPI names, absolute URLs, and micropip specs are untouchedtests/test_asset_href.py) and a nested-page HTML build test (tests/test_nested_static_paths.py)Behavior
index.html_static/wheels/foo.whl_static/wheels/foo.whl(unchanged)api/index.html_static/wheels/foo.whl../_static/wheels/foo.whlTest plan
pytest tests/— 41 passedapi/index.rstasserts page-relative paths in output