Skip to content

Conversation

@mmcky
Copy link
Contributor

@mmcky mmcky commented Dec 8, 2025

Problem

When path_to_docs is configured (e.g., lectures), Sphinx passes pagenames with this prefix (e.g., lectures/jax_intro). If the notebook repository has a flat structure (no nb_path_to_notebooks configured), this causes incorrect URLs:

Before: https://colab.research.google.com/.../blob/main/lectures/jax_intro.ipynb
After: https://colab.research.google.com/.../blob/main/jax_intro.ipynb

Solution

Strip the path_to_docs prefix from the pagename before constructing notebook URLs. This ensures:

  • Flat notebook repos work correctly with docs in subdirectories
  • nb_path_to_notebooks (if configured) is still correctly applied
  • Backward compatible with existing configurations

Changes

  • Modified launch.py to strip path_to_docs from pagename before URL construction
  • Added comprehensive test coverage for this scenario

Testing

pytest tests/test_build.py::test_add_hub_urls_path_to_docs_stripping -v

Context

Fixes issue where PR previews showed malformed Colab links with incorrect paths. This occurred when the source documentation was in a subdirectory (configured via path_to_docs) but the notebook repository had a flat structure.

When path_to_docs is configured (e.g., 'lectures'), the pagename includes
this prefix. However, when the notebook repository has a flat structure
(no nb_path_to_notebooks configured), we should strip the path_to_docs
prefix to avoid incorrect URLs like 'lectures/jax_intro.ipynb' when the
correct URL should be 'jax_intro.ipynb'.

This fix ensures that:
- path_to_docs is stripped from pagename before constructing notebook URLs
- nb_path_to_notebooks (if configured) is still correctly prepended
- Works correctly for both flat and nested notebook repository structures

Adds comprehensive test coverage for this scenario.
@codecov
Copy link

codecov bot commented Dec 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@af02c15). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #345   +/-   ##
=======================================
  Coverage        ?   45.21%           
=======================================
  Files           ?        2           
  Lines           ?      387           
  Branches        ?        0           
=======================================
  Hits            ?      175           
  Misses          ?      212           
  Partials        ?        0           
Flag Coverage Δ
pytests 45.21% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mmcky
Copy link
Contributor Author

mmcky commented Dec 8, 2025

  • @mmcky to look at this more deeply as it was a fix applied to an issue being reported (that was due to machine issues).

@github-actions
Copy link

github-actions bot commented Dec 8, 2025

🎭 Visual Regression Test Results

passed  37 passed
skipped  1 skipped

Details

stats  38 tests across 1 suite
duration  49.7 seconds
commit  6372450

Skipped tests

mobile-chrome › theme.spec.ts › Theme Features › f-string interpolation styling

@github-actions
Copy link

github-actions bot commented Dec 8, 2025

@github-actions github-actions bot temporarily deployed to pull request December 8, 2025 05:24 Inactive
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes incorrect notebook URLs when documentation source files are in a subdirectory (path_to_docs) but the notebook repository has a flat structure. The fix strips the path_to_docs prefix from the pagename before constructing notebook repository URLs, ensuring the URLs point to the correct location in the notebook repository while maintaining backward compatibility.

Key changes:

  • Modified launch.py to strip path_to_docs from pagename when constructing notebook URLs
  • Added comprehensive test coverage for the new path stripping functionality
  • Ensured compatibility with both flat notebook repositories and those using nb_path_to_notebooks

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/quantecon_book_theme/launch.py Adds logic to strip path_to_docs prefix from pagename before constructing notebook URLs, fixing malformed Colab/JupyterHub links
tests/test_build.py Adds test_add_hub_urls_path_to_docs_stripping function with two test scenarios covering flat repos and repos with nb_path_to_notebooks

@github-actions github-actions bot temporarily deployed to pull request December 10, 2025 21:47 Inactive
Addresses Copilot review comment: adds explicit test case verifying that
when pagename doesn't start with path_to_docs prefix, the pagename is
used as-is without modification.
@github-actions github-actions bot temporarily deployed to pull request December 10, 2025 22:42 Inactive
@mmcky mmcky merged commit d434e2c into main Dec 10, 2025
10 checks passed
@mmcky mmcky deleted the fix/strip-path-to-docs-from-notebook-urls branch December 10, 2025 22:43
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