Skip to content

PML-387 & PML-389: fixed user path in documentation#281

Open
CassNot wants to merge 3 commits into
merlinquantum:mainfrom
CassNot:generating-0.4-doc
Open

PML-387 & PML-389: fixed user path in documentation#281
CassNot wants to merge 3 commits into
merlinquantum:mainfrom
CassNot:generating-0.4-doc

Conversation

@CassNot

@CassNot CassNot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

When building the doc on the server, it was using my path for the images in the notebook and there were errors displaying them.
Now, the multiversion builder now passes a per-version -d doctree directory inside the exported tag checkout. That keeps nbsphinx image artifacts relative to the source tree, so Sphinx copies them into _images instead of rendering /Users/.../.doctrees/nbsphinx/... paths.
I changed these lines, compiled and sent to the server and it is now fixed on merlinquantum.ai !

Related Issue

PML-387

Type of change

  • Bug fix
  • New feature
  • Documentation update
  • Refactor / Cleanup
  • Performance improvement
  • CI / Build / Tooling
  • Breaking change (requires migration notes)

Proposed changes

The multiversion builder now passes a per-version -d doctree directory inside the exported tag checkout. That keeps nbsphinx image artifacts relative to the source tree, so Sphinx copies them into _images instead of rendering /Users/.../.doctrees/nbsphinx/... paths.

How to test / How to run

Go on merlinquantum.ai

Checklist

  • PR title includes Jira issue key (e.g., PML-126)
  • "Related Jira ticket" section includes the Jira issue key (no URL)
  • Code formatted (ruff format)
  • Lint passes (ruff)
  • Static typing passes (mypy) if applicable
  • Unit tests added/updated (pytest)
  • Tests pass locally (pytest)
  • Tests pass on GPU (pytest)
  • Test coverage not decreased significantly
  • Docs build locally if affected (sphinx)
  • With this command: SPHINXOPTS="-W --keep-going -n" make -C docs clean html the docs are built without any warning or errors.
  • New public classes/methods/packages are added in the API following the methodology presented in other files.
  • Dependencies updated (if needed) and pinned appropriately
  • PR description explains what changed and how to validate it

@CassNot CassNot added documentation Improvements or additions to documentation bugfix labels Jul 8, 2026
@CassNot
CassNot requested a review from ben9871 July 8, 2026 20:56
@CassNot CassNot changed the title PML-387: fix/doc multiversion: fixed path so it uses doctree path and not rela… PML-387: fixed user path in documentation Jul 8, 2026
@CassNot CassNot added this to the v0.4.1 milestone Jul 14, 2026
@CassNot

CassNot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

@ben9871 , I just updated my branch to add a new fix for PML-389 that was just detected
We did not have redirection from former documentation pages. For instance https://merlinquantum.ai/reproduced_papers/index.html was failing with error 404 instead of redirecting to https://merlinquantum.ai/0.4/reproduced_papers/index.html or more generally https://merlinquantum.ai/latest_version/reproduced_papers/index.html
This is now fixed: https://merlinquantum.ai/reproduced_papers/index.html now serve a stub page that immediately redirects (meta-refresh + canonical link) to the equivalent page under the latest version ( here /0.4/...), instead of 404 error
This was pushed to merlinquantum.ai and works

@claude review this fix and my PR

@claude

claude Bot commented Jul 15, 2026

Copy link
Copy Markdown

Claude finished @CassNot's task in 2m 21s —— View job


Review: PR #281 — PML-387 (nbsphinx paths) + PML-289 (legacy redirects)

  • Read the PR diff
  • Analyze the doctree/nbsphinx fix (PML-387)
  • Analyze the legacy redirect fix (PML-289)
  • Post review feedback

Nice work — both changes are well-structured, the docstrings match the file's existing numpydoc style, and factoring the shared redirect HTML into _redirect_page is a good cleanup. The path-traversal guard and the index skip are thoughtful touches. I found one real bug worth fixing before merge, plus a couple of minor notes.


🔴 Bug: .with_suffix(".html") mangles docnames containing dots

docs/build_multiversion.py:348

legacy_path = (output_path / docname).with_suffix(".html")

Path.with_suffix() replaces everything after the last dot in the final path component, not just a source suffix. Many docnames in this repo contain dots — the entire auto-generated API reference does, e.g. api_reference/api/merlin.algorithms.feed_forward:

docname stub written at (buggy) should be
api_reference/api/merlin.algorithms.feed_forward .../api/merlin.algorithms.html .../api/merlin.algorithms.feed_forward.html
api_reference/api/merlin.algorithms.layer .../api/merlin.algorithms.html .../api/merlin.algorithms.layer.html
api_reference/api/merlin.algorithms.loss .../api/merlin.algorithms.html .../api/merlin.algorithms.loss.html

Two consequences:

  1. The stub is written at the wrong path, so the actual old URL (.../merlin.algorithms.feed_forward.html) still 404s — exactly what PML-289 is meant to fix.
  2. Collisions overwrite each other — every merlin.algorithms.* page collapses to a single merlin.algorithms.html, so only the last one written survives (as junk).

Note target_url on line 356 uses the raw docname string, so the target is correct — only the filename is wrong. The fix is to build the filename by string concatenation instead:

legacy_path = output_path / f"{docname}.html"

The depth = docname.count("/") / relative_prefix logic is unaffected and stays correct (I verified reproduced_papers/index../0.4/reproduced_papers/index.html resolves properly, and depth-0 pages too).

Fix this →


🟢 PML-387 (doctree -d fix) — looks good

docs/build_multiversion.py:411,429-430 — passing an explicit per-version -d doctree dir inside the exported checkout is a sound way to keep nbsphinx image artifacts relative to the source tree, and you've verified it on merlinquantum.ai. Minor observations (non-blocking):

  • checkout_path is already unique per version, so the extra / version_name on the doctree path is redundant (harmless).
  • The doctrees live in the temp checkout that's cleaned up with the TemporaryDirectory, so there's no cache reuse between runs — expected for this script, just noting it.

🟡 Minor notes (optional)

  • HTML escaping in _redirect_pagetarget_url/link_text are interpolated into attributes without escaping. Docnames won't contain " in practice, so this is only a robustness nit.
  • docnames for redirects — you correctly use only the latest version's docnames, which is the right behavior for landing users on current content. Worth a one-line comment noting a page removed in the latest version won't get a redirect (acceptable).

Overall: solid fix. The only thing I'd block on is the with_suffix issue, since it breaks redirects for every dotted-name page (the whole API reference). Once that's a plain f"{docname}.html", this looks ready.
· branch generating-0.4-doc

@CassNot CassNot changed the title PML-387: fixed user path in documentation PML-387 & PML-389: fixed user path in documentation Jul 15, 2026
@CassNot

CassNot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

It should be fixed now @claude review

@claude

claude Bot commented Jul 15, 2026

Copy link
Copy Markdown

Claude finished @CassNot's task in 38s —— View job


Re-review: PML-387 + PML-389 — with_suffix fix

  • Read the updated diff (commit 9af3262)
  • Verify the dotted-docname bug is fixed
  • Confirm the rest of the change still holds up

The bug is fixed. Line 355 now builds the filename by string concatenation:

legacy_path = output_path / f"{docname}.html"

This correctly handles docnames containing dots. I traced the API-reference case that was previously broken:

docname stub written at (now) target_url
api_reference/api/merlin.algorithms.feed_forward .../api/merlin.algorithms.feed_forward.html ../../0.4/api_reference/api/merlin.algorithms.feed_forward.html
api_reference/api/merlin.algorithms.layer .../api/merlin.algorithms.layer.html ../../0.4/.../merlin.algorithms.layer.html

No more collisions, and each old URL resolves to its correct versioned target. The explanatory comment on lines 348–354 is a nice touch — it documents exactly why with_suffix() was wrong, which will save the next person from reintroducing it.

I re-verified the surrounding logic is unaffected:

  • Path-traversal guard (line 358) still works — output_path.resolve() is in legacy_path.resolve().parents for both nested (reproduced_papers/index) and top-level (changelog) docnames, and rejects a leading ...
  • depth/relative_prefix (lines 361–363) — count("/") is unaffected by dots; reproduced_papers/index../0.4/reproduced_papers/index.html and depth-0 pages → 0.4/<name>.html both resolve correctly.
  • index skip (line 346) correctly defers to write_latest_redirect.

Verdict

The one blocking issue from my previous review is resolved. Both fixes (PML-387 doctree -d, PML-389 legacy redirects) look correct and ready to merge.

The two earlier minor notes remain optional and non-blocking:

  • HTML escaping of target_url/link_text in _redirect_page (docnames won't contain " in practice).
  • Redirects only cover pages present in the latest version (correct behavior; a page removed in the latest version won't get a redirect).

Nice work. 👍
· branch generating-0.4-doc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants