Skip to content

Un-flatten JupyterLite contents: preserve notebook paths and directory structure - #337

Merged
martinRenou merged 4 commits into
jupyterlite:mainfrom
agriyakhetarpal:don't-flatten-notebooks
Aug 11, 2026
Merged

Un-flatten JupyterLite contents: preserve notebook paths and directory structure#337
martinRenou merged 4 commits into
jupyterlite:mainfrom
agriyakhetarpal:don't-flatten-notebooks

Conversation

@agriyakhetarpal

@agriyakhetarpal agriyakhetarpal commented Feb 25, 2026

Copy link
Copy Markdown
Member

Previously, when support for Markdown-based notebooks was added in #221, we added mechanisms to handle potential notebook name collisions and hoped that no one in the wild would have two notebooks of the same name across their docs directories and subdirectories. This is because we currently "flatten" all notebooks marked for inclusion on the JupyterLite site via directives into a single /path/to/docs/lite/files/ folder. I have started to think that it is a bad idea, since the contemporary Sphinx-Gallery does not do that as part of its JupyterLite integration and preserves the entire nested structure of the notebooks.

This PR stops doing so. We can now have notebooks with the same filename, say, my_notebook.ipynb, placed in two distinct folders, as the directory structure will be preserved. We can't have notebooks of the same filename under the same folder anyway, as that will be restricted by the file system :D

I have removed the _assert_no_conflicting_nb_names check and preserved relative notebook paths when converting/copying. Additionally, jupyterlite_contents entries that are directories are now copied into the _contents/ staging area rather than being passed directly as --contents arguments to jupyter lite build. This will help preserve the directory name in the JupyterLite file system: previously, passing --contents custom_contents caused JupyterLite to treat that directory as a content root, placing its files at the root of files/ rather than under files/custom_contents/. Routing them through _contents/, which is already passed as a single --contents argument, ensures the directory name will be retained.

@agriyakhetarpal agriyakhetarpal added the enhancement New feature or request label Feb 25, 2026
@agriyakhetarpal agriyakhetarpal added this to the 0.23.0 milestone Feb 25, 2026
@agriyakhetarpal

Copy link
Copy Markdown
Member Author

@mfisher87, I noticed that you opened #307. This is sort of related to the issue, since it should partially fix the flattening out of the examples/ directory you had. I would appreciate you taking a look, so that we don't have any unexpected behaviour and can catch things in advance for JupyterGIS! 😄 That said, you mentioned including some info in the docs about how the globs work when specified in jupyterlite_contents. I would welcome such a PR post these changes, however they land in the end. I myself have had some confusion on how jupyterlite_contents should work on a few occasions in the past.

  • I believe the case where examples/** is specified duplicates files will remain with this PR
  • If ../examples (without any glob) is specified, the files will appear under files/examples/ and won't be flattened, but I am not sure if any users are relying on the current behaviour in weird ways

@martinRenou

Copy link
Copy Markdown
Member

I took the liberty to rebase and fix conflicts, hope you don't mind!

@martinRenou
martinRenou merged commit 481c0ed into jupyterlite:main Aug 11, 2026
5 checks passed
@agriyakhetarpal
agriyakhetarpal deleted the don't-flatten-notebooks branch August 11, 2026 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants