-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How would this use jupyter-cache
?
#32
Comments
@chrisjsewell is this what you had in mind? |
Yep that seems like the general idea. The one thing I'm considering is whether to match the notebooks by URI or a hash, but that wouldn't entail much change to the code. |
Does that mean 1 notebook per source file? |
What if there isn't an output corresponding to the notebook? |
Are you thinking here about how |
Yes, indeed. |
Well yeh that won't be the case here. It will be one kernel per source file. It's just not possible to have round-trip conversion with a multi-kernel file. |
Unless you see any added benefit to have multiple kernels in a single source file? |
Is the round-trip conversion a goal? It seems absent from the v3 pipeline of executablebooks/meta#21
Not really. If there's a clear way to combine multiple source files into one HTML output, that seems to be a cleaner optimal solution. I do think there's a use case to having multiple kernels per HTML page. |
100%, its part of section 1 in the pipeline; you have to be able to switch between writing code (most probably in the notebook form) and writing documentation / what you commit to git (most likely the MyST format file). This will likely use jupytext |
@akhmerov I don't think that this should preclude the existence of tooling that lets you have multiple kernels per sourcefile, but for the scope of |
Given executablebooks/jupyter-cache#8:
This is no longer the case; you just 'give' it a notebook and it will give you back a pointer (primary key) to the one in the cache (matched by hash) or raise a
You can either grab the entire notebook (plus artefacts);
Yes, and an option to specify the path to the cache. |
Now all you have to do is: cache = JupyterCacheBase("path/to/the/cache")
try:
# this will give you the "final" notebook with all outputs populated
pk, notebook = cache.merge_match_into_notebook(notebook)
# you may also want to copy execution artefacts to the build folder
with cache.commit_artefacts_temppath(pk) as folder:
shutil.copytree(folder, "path/in/build/folder")
except KeyError:
# a match was not found
pass |
Once
jupyter-cache
is ready for prototyping etc, we should also figure out how to use it as a part of building Sphinx sites with notebooks. Here is one way to do it:Each notebook will have a unique URI in the cache that is tied to its location on disk. In Sphinx, when we parse a source file we also have the file location of that file. So, when a source file is parsed that also has a key in the Jupyter Cache registry, then instead of pulling
cell['outputs']
and inserting it into the cell mimebundle, we could instead grab those outputs from the cache. From then on, everything proceeds as normal. (somewhere around https://github.com/ExecutableBookProject/myst-nb/blob/master/sphinx_notebook/parser.py#L80)So it would be something like the following (and assuming that the cache had already been run and cached before Sphinx entered the equation)
.jupyter_cache
to see if there's a URI for the file.cell['output']
.The text was updated successfully, but these errors were encountered: