mkdocs-jupyter
mkdocs-jupyter copied to clipboard
Ignored `.md` files should not be read with `jupytext`
As I also explained in https://github.com/mwouts/jupytext/issues/1306#issuecomment-2763639640, the Plugin.should_include at https://github.com/danielfrg/mkdocs-jupyter/blob/a3cded5b3a7b14327196c98ffbc7558ce7d267ae/src/mkdocs_jupyter/plugin.py#L60-L86 will attempt to read any .md with jupytext.read, even if .md files are configured to not be included, or to be ignored.
In https://github.com/jorenham/lmo/, this results in many confusing warning messages to be logged to stderr, specifically, the following is printed 12x when I run uv mkdocs build:
INFO - MissingIDFieldWarning: Cell is missing an id field, this will become a hard error in future nbformat versions. You may want to use `normalize()` on your notebooks before validations (available since nbformat 5.1.4). Previous versions of nbformat are fixing this issue transparently, and will stop doing so in the future.
File "/home/joren/Workspace/lmo/.venv/lib/python3.12/site-packages/nbformat/validator.py", line 351, in _normalize
warnings.warn(
File "/home/joren/Workspace/lmo/.venv/lib/python3.12/site-packages/nbformat/__init__.py", line 96, in
validate(nb)
As you can see from https://github.com/mwouts/jupytext/issues/1306, it took me many hours to figure this out, so I think I at least deserve a cookie now. And it would be even better if this could be fixed :)
seeing this as well. ignore option doesn't work. please fix. thanks
The underlying issue seems to be that jupytext parses the mkdocstrings autodoc syntax without errors but (unsurprisingly) complains about its formatting. For example:
import jupytext
jupytext.reads("::: foo", fmt="md")
.../lib/python3.12/site-packages/nbformat/__init__.py:96: MissingIDFieldWarning: Cell is missing an id field, this will become a hard error in future nbformat versions. You may want to use `normalize()` on your notebooks before validations (available since nbformat 5.1.4). Previous versions of nbformat are fixing this issue transparently, and will stop doing so in the future.
validate(nb)
As @jorenham found, mkdocs-jupyter parses every Markdown file with jupytext before checking ignore patterns, so every Markdown file with mkdocstrings syntax throws that warning, even if the file is ignored.
Whether or not ::: foo should be a parseable input for jupytext, checking the ignore patterns first in Plugin.should_include seems like an easy fix, as that would resolve this issue (and avoid some unnecessary parsing) for users who are explicitly ignoring .md files.
I'm happy to make a PR with that fix.