mkdocstrings: jinja2.exceptions.TemplateNotFound: alias.html
Describe the bug
While running mkdocs build I get an exception:
$ mkdocs build
INFO - Cleaning site directory
INFO - Building documentation to directory: C:\Users\lameg\kubekind\site
WARNING - mkdocstrings_handlers: 1 aliases were still unresolved after 2 iterations
ERROR - mkdocstrings: Template 'alias.html' not found for 'python' handler and theme 'material'.
ERROR - Error reading page 'index.md': alias.html
Traceback (most recent call last):
File "C:\Users\lameg\miniforge3\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\lameg\miniforge3\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\lameg\miniforge3\Scripts\mkdocs.exe\__main__.py", line 7, in <module>
File "C:\Users\lameg\miniforge3\lib\site-packages\click\core.py", line 1137, in __call__
return self.main(*args, **kwargs)
File "C:\Users\lameg\miniforge3\lib\site-packages\click\core.py", line 1062, in main
rv = self.invoke(ctx)
File "C:\Users\lameg\miniforge3\lib\site-packages\click\core.py", line 1668, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "C:\Users\lameg\miniforge3\lib\site-packages\click\core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Users\lameg\miniforge3\lib\site-packages\click\core.py", line 763, in invoke
return __callback(*args, **kwargs)
File "C:\Users\lameg\miniforge3\lib\site-packages\mkdocs\__main__.py", line 192, in build_command
build.build(config.load_config(**kwargs), dirty=not clean)
File "C:\Users\lameg\miniforge3\lib\site-packages\mkdocs\commands\build.py", line 292, in build
_populate_page(file.page, config, files, dirty)
File "C:\Users\lameg\miniforge3\lib\site-packages\mkdocs\commands\build.py", line 174, in _populate_page
page.render(config, files)
File "C:\Users\lameg\miniforge3\lib\site-packages\mkdocs\structure\pages.py", line 175, in render
self.content = md.convert(self.markdown)
File "C:\Users\lameg\miniforge3\lib\site-packages\markdown\core.py", line 264, in convert
root = self.parser.parseDocument(self.lines).getroot()
File "C:\Users\lameg\miniforge3\lib\site-packages\markdown\blockparser.py", line 90, in parseDocument
self.parseChunk(self.root, '\n'.join(lines))
File "C:\Users\lameg\miniforge3\lib\site-packages\markdown\blockparser.py", line 105, in parseChunk
self.parseBlocks(parent, text.split('\n\n'))
File "C:\Users\lameg\miniforge3\lib\site-packages\markdown\blockparser.py", line 123, in parseBlocks
if processor.run(parent, blocks) is not False:
File "C:\Users\lameg\miniforge3\lib\site-packages\mkdocstrings\extension.py", line 121, in run
html, handler, data = self._process_block(identifier, block, heading_level)
File "C:\Users\lameg\miniforge3\lib\site-packages\mkdocstrings\extension.py", line 209, in _process_block
rendered = handler.render(data, options)
File "C:\Users\lameg\miniforge3\lib\site-packages\mkdocstrings_handlers\python\handler.py", line 215, in render
template = self.env.get_template(f"{data.kind.value}.html")
File "C:\Users\lameg\miniforge3\lib\site-packages\jinja2\environment.py", line 1010, in get_template
return self._load_template(name, globals)
File "C:\Users\lameg\miniforge3\lib\site-packages\jinja2\environment.py", line 969, in _load_template
template = self.loader.load(self, name, self.make_globals(globals))
File "C:\Users\lameg\miniforge3\lib\site-packages\jinja2\loaders.py", line 126, in load
source, filename, uptodate = self.get_source(environment, name)
File "C:\Users\lameg\miniforge3\lib\site-packages\jinja2\loaders.py", line 218, in get_source
raise TemplateNotFound(template)
jinja2.exceptions.TemplateNotFound: alias.html
To Reproduce Steps to reproduce the behavior:
git clone git@github.com:joaompinto/kubekind.git
cd kubekind
pip install mkdocs mkdocstrings mkdocstrings[python]
mkdocs build
Expected behavior A clear and concise description of what you expected to happen.
Information (please complete the following information):
- OS: Windows 10
- mkdocstrings 0.19.0
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 33 (15 by maintainers)
Commits related to this issue
- set __module__ to "blake3.blake3" in the Rust implementation This is a correction of 07c389f257db6d3fa1fa00385b49c6b0fd262d60, which originally set `__module__` to "blake3". For all the details, see:... — committed to oconnor663/blake3-py by oconnor663 2 years ago
- version 0.3.3 Changes since 0.3.2: - Change `blake3.__module__` from "blake3" to "blake3.blake3". This is the correct canonical path, related to some Maturin implementation details. This is inten... — committed to oconnor663/blake3-py by oconnor663 2 years ago
- version 0.3.3 Changes since 0.3.2: - Change `blake3.__module__` from "blake3" to "blake3.blake3". This is the correct canonical path, related to some Maturin implementation details. This is inten... — committed to oconnor663/blake3-py by oconnor663 2 years ago
Ah interesting. It looks like that’s an implementation detail of the Maturin build tool. I’ve opened a discussion question about best practices here: https://github.com/PyO3/maturin/discussions/1365. Please chime in if you have any thoughts about Maturin/PyO3, or if you can clarify exactly how the
mkdocstool is getting confused. (I’m not familiar with it.)Just published
blake3v0.3.3 with__module__set toblake3.blake3. Could you give this another try?The Maturin maintainer has asked for repro steps here: https://github.com/PyO3/maturin/discussions/1365#discussioncomment-4454070. Could someone from this thread add a
mkdocsrepro to that thread?As I tried to explain before,
::: blake2signer.hashers.blake3will not make Griffe load theblake3package, so you won’t have any information about theblake3class.The idea is that later, you’ll be able to use something like this:
…so that you don’t have to rely on this hidden div hack 🙂
Indeed, it does work when I do something like explained here 😄 🥳
It still fails if I use
::: blake2signer.hashers.blake3instead of::: blake3, but this is good enough 😅Seems to be working fine! I’ll let @HacKanCuBa confirm 🙂
Your toy example is correct, however your code/project has one more layer:
Generally, it seems that objects do have the full, canonical path to the module they are defined in as value for
__module__. Some examples:I wonder if this is because @oconnor663 set the parent to module to
blake3instead ofblake3.blake3🤔Hmmm interesting, I do not see that
griffeissue in my log:This line caught my attention:
Alias resolution error for blake2signer.hashers.blake3 -> blake3.blake3:blake2signer.hashers.blake3does not exists per se,hashersis a module, andblake3is an import from a submodule in__init__.py:from .blake3_package import blake3. It seems that Griffe is having issues w/ that.This is referenced in a doc file as:
::: blake2signer.hashers, andblake3does not appear in the rendered docs.If I instead reference directly
blake2signer.hashers.blake3, as::: blake2signer.hashers.blake3, I get this exception, and the build fails:This is from my open-source project, you can build the docs yourself if needed: https://gitlab.com/hackancuba/blake2signer/
git clone git@gitlab.com:hackancuba/blake2signer.gitcd blake2signercd docspoetry install(a.venvdir is automatically created locally by Poetry)poetry run mkdocs build -vThanks a lot. i’ll try to find some time the next days to setup a simplified project-repo to reproduce the error.