Skip to content

build-lectures: html-copy-notebooks flattens the notebooks, so a nested page's download link leads nowhere #217

Closed

Description

@quantecon-services

Found while fact-checking the build-lectures chapter of the user manual (#190, #213).

What happens

With html-copy-notebooks: 'true', build-lectures copies every notebook from _build/jupyter into _build/html/_notebooks/, flat (build-lectures/action.yml, "Stage notebooks for HTML build"):

find "$NB_SOURCE" -name "*.ipynb" -exec cp {} "$NB_DEST/" \;

The jupyter build keeps the book's directories, and quantecon-book-theme links each page to its notebook with the page's directory in the path. In 0.22.0, the version the images pin (quantecon_book_theme/__init__.py:596-605):

context["notebook_path"] = "/_notebooks/" + context["pagename"] + ".ipynb"

So:

  • A page in a subdirectory gets a link to /_notebooks/<dir>/<page>.ipynb, but its notebook was copied to /_notebooks/<page>.ipynb. The download link leads nowhere.
  • Two notebooks with the same name in different directories overwrite each other, silently.

A book whose lectures are all at the top of source-dir, as most QuantEcon lecture repositories are, is not affected.

Proposed fix

Copy with the relative path kept, for example:

(cd "$NB_SOURCE" && find . -name '*.ipynb' -exec cp --parents {} "$NB_DEST/" \;)

The PDF copy can stay flat: the theme links one book PDF, /_pdf/<LaTeX document name>.pdf.

A harness test would need a nested page in the fixture's jupyter and html builds, with an assertion that _build/html/_notebooks/<dir>/<page>.ipynb exists.

Related, not in this repository

Both of the theme's download links start at the site's root, /_notebooks/… and /_pdf/…. So they lead nowhere on a site served under a path, such as a GitHub Pages project site with no custom domain. The theme's download_nb_path option sets a prefix for the notebook links; the PDF link has none. That belongs to QuantEcon/quantecon-book-theme.

The manual's build-lectures chapter (#213) states both limits and links here.

Activity

  1. added
    bug
    on Sep 28, 2026
  2. mmcky commented on Nov 6, 2026

    @mmcky
    Contributor

    Checked against main at 9644f17 (2026-11-06): the bug stands, but the fix needs two revisions. The copy is still flat (build-lectures/action.yml:181). sphinx-tojupyter 0.6.0 still writes _build/jupyter/<dir>/<page>.ipynb. quantecon-book-theme's link code is the same in 0.22.1, which the full image pins, and in 0.22.2, which the lean image now has (src/quantecon_book_theme/__init__.py:596-605). No caller is affected today: the only callers that set html-copy-notebooks are the canary and QuantEcon/test-lecture-theme-sphinx, and the canary's lectures are all at the top level.

    First, the proposed command stages nothing as written. NB_DEST is relative to the workspace (./_build/html/_notebooks by default), so after the cd into _build/jupyter it points at a directory that does not exist. Every cp then fails, and a failed -exec … \; does not fail find, so the step passes having copied nothing. cp --parents is also GNU-only. The revision copies each notebook to the same relative path under _notebooks/ without a cd, with a find -print0 loop that runs mkdir -p and cp for each notebook, so a failed copy now fails the step. The PDF copy stays flat. It has the same -exec cp … \; (build-lectures/action.yml:158), so it gets -exec sh -c 'cp "$@" "$0"' "$PDF_DEST/" {} +, which makes find exit non-zero when cp fails. The shorter -exec cp {} "$PDF_DEST/" + is refused by find, which needs {} just before the +.

    Second, the test is now small. #265 added the build-html-copy harness job, which puts stand-in files in _build/jupyter and checks the copies. A stand-in sub/lecture1.ipynb beside the top-level lecture1.ipynb checks both halves of this bug, the nested path and the name collision, and it fails against main today. The fixture needs no nested page.

    The fix also updates the html-copy-notebooks description and the chapter's two caveats (docs/user/actions/build-lectures.md:127, :152). It is not breaking: top-level notebooks land where they did. The theme's root-relative links stay with QuantEcon/quantecon-book-theme.

    Claude Code (on behalf of mmcky)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions