-
Notifications
You must be signed in to change notification settings - Fork 190
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
Add support for include directives #80
Conversation
@mmcky this was triggered by your question, even though it wasn't actually for includes 😆 |
Where is the restriction of the same filetype come from? |
Because .. include:: include.html |
Following from the above comment, it's also important to note that any relative file references in the included document will be read as relative to the importing/parent file. See this issue: https://stackoverflow.com/a/50261574/5033292. (FYI in LaTex you also have the import package which 'fixes' this issue with relative paths) Although this is a docutils/sphinx related matter, maybe it would be helpful to talk about this behavior in the MyST documentation? |
Also parse content to directive as `StringList`, which allows 'glossary' directive to work, and fix `document.source` -> `document["source"]`
I'm +1 on documenting this feature in the docs! Am I correct in thinking that we needed this PR because the |
Well it was one of the 'edge-case' directives that didn't work with the minimal docutils 'Mock' classes that cover most of the core docutils/sphinx directives, because they call extra attributes/methods that haven't yet been implemented. With enough mocked methods it probably wouldn't be a special case, but actually I think I've done a better job than the docutils code, of ensuring that errors are reported correctly; pointing to the correct included document, and correct source text line number. In this PR I've also actually added some more methods to cover the |
Added #81 for that, so I'll merge this, unless you want to check over any of the code/circleCI artefacts @choldgraf? |
Does it actually cover the use case of executablebooks/MyST-NB#32 (combining multiple kernels in one file)? |
For text-based documents, i.e. |
Yeah, I was wondering about the notebooks, or otherwise files that don't have an directive for specifying the kernel, but provide the kernel either in the front matter, or metadata. It seems that the AST resulting from the inclusion of several such files should contain several instances of the jupyter-sphinx kernel nodes or equivalent. That, in turn, would seem to require postprocessing the output of the parsing. |
Well that's if you actually require a 'kernel node'. Surely you only need this if you intend to execute the notebooks after the parsing phase? MyST-NB doesn't currently use any such node, because it assumes the notebooks are pre-executed. Then if you're (hopefully at some point) using the
Each 'included' notebook here, and its outputs, are dealt with at the time it is parsed/included. The only post-processing then is what MyST-NB already does with mime-bundles. |
I thought that querying the cache would happen after the parsing—at least that was in your previous proposal. This is also why I thought that keeping the kernel node is important, since otherwise one cannot obtain the cache key. You're saying it'd be done differently now? |
Yep. I reserve the right to flip-flop in my proposals 😆 I (now) think it works better with 'getting the execution done early', because (a) it makes it easier to separate the execution from the documentation generation, (b) you have less post-processing to deal with. |
On the other hand, if the execution and treating outputs is done before parsing, then it needs to be implemented once per file format. Say one wants to keep some rst files? |
Why once per file format? You just gather all files that can be converted to notebooks (e.g. have a jupytext converter) and stage them on the cache. Note we are doing an initial 'fast' parse here, whereby we just want to identify the kernel and code-cells and don't need to tokenize the whole document. This may make it a bit slower than doing a single parse and post-processing, but makes the process a lot more robust and easy(ish) to implement. Thinking about it now, during this 'fast' parse phase, we would store a mapping of each document's docame -> hash (the one for code+kernel) in the sphinx env. Then at the parsing stage, we could quickly retrieve it, without the need for a second parse.
Not sure what you mean by 'keep' here? Nothing is actually changed in the sphinx source folder, just the cache is updated. |
As in "keep using". Jupytext doesn't have an rst reader, AFAIK, and therefore the workflow you propose would mean implementing this. At the same time generating a sphinx AST is the one thing all formats for the EBP have in common. |
Well we can discuss this more on MyST-NB, but for now, I'm going to merge this 😄 |
MyST now supports the
include
directive! Seetests/test_sphinx/sourcedirs/includes
andtests/test_sphinx/test_sphinx_builds
for an example sphinx project with includes, and it's build outputs.@choldgraf and @akhmerov, given the discussion in executablebooks/MyST-NB#32,
over having multiple kernels on a single HTML page. You should be able to just use this out-of-the box to work with the current
jupter-sphinx
and multiple MyST files:Note:
**/*.ipynb.md
should be in theexclude_patterns
so they are not executed twice.The
include
directive only works though for including documents of the same type (e.g. md ->md or rst -> rst) if you want to actually parse the file content. So it would be interesting to consider if/how something like aninclude-nb
directive could work, for stitching multiple notebooks into one MyST file: