jupyterlite-sphinx icon indicating copy to clipboard operation
jupyterlite-sphinx copied to clipboard

jupyterlite_contents paths not picked up if run from outside of app.srcdir

Open LoicGrobol opened this issue 10 months ago • 2 comments

When the top build command is run outside of Sphinx' srcdir (which is the case when buliding from Jupyterbook for instance) the following happens:

  1. jupyterlite_contents path are expanded with glob using the cwd as root. This means that paths that don't exist after expansion are removed from the list.
  2. jupyter lite build is invoked using app.srcdir as cwd.

So say I have the following structure

repo
└── book
    ├── conf.py
    └── notebooks
        └── nb.ipynb

To build the book, I have to run Jupyterbook in repo and I want notebooks/ to be in jupyterlite_contents.

  • If I set jupyterlite_contents = ["book/notebooks"], glob in 1. will be able to find it since for glob, the root dir is repo, but when jupyter lite build runs in 2., since its cwd is book, it won't find book/notebooks and the build will fail.
  • If I set jupyterlite_contents = ["notebooks"] instead, glob in 1. won't find it, sot it will silently remove it from the list. The build will succeed but the notebook won't be picked up.

Either way, I can't get notebook in my build if it's not run from app.srcdir.

A simple fix would be to set glob's rootdir parameter to src.appdir. It would still allow adding paths outside of the appdir using ... I can send a PR as soon as I have you go, or as soon as we figure out another solution if this one doesn't work, as I am very interested in having this fixed :-)

LoicGrobol avatar Jan 25 '25 12:01 LoicGrobol

Hi @LoicGrobol, thanks for the report and sorry for the late response! I think this bug report is valid, but I'm unsure if I follow it correctly, so I want to seek some clarification(s). :)

  1. Could you please explain how you're running jupyterlite-sphinx? If I understand this correctly, it is Jupyter Book that's setting this requirement, as it might be running python sphinx -b html --conf-dir ./book/ internally from the repo folder?

  2. Your suggested fix is to set the rootdir parameter for glob.glob here: https://github.com/jupyterlite/jupyterlite-sphinx/blob/6f7aa459219e7d98921a65b14efe1e6be3b6e8aa/jupyterlite_sphinx/jupyterlite_sphinx.py#L991-L1001 Would it better if we were to allow absolute paths here as well, so that we aren't bound to looking just in app.srcdir?

Either way, I'm happy to accept a PR for the changes, and we can release it as soon as possible – as we already have a bunch of fixes going in sooner or later. Thanks a lot!

agriyakhetarpal avatar Feb 03 '25 12:02 agriyakhetarpal

Hi @LoicGrobol, I've started a solution in #280 that should allow using relative paths using ../<...>/ and also absolute paths to any directory on your system. Please feel free to comment on this approach, and I hope this resolves your issue!

agriyakhetarpal avatar Apr 11 '25 11:04 agriyakhetarpal