Skip to content
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

bug: regression on windows since 1.7.4 #116

Closed
AntoineD opened this issue Nov 28, 2023 · 6 comments
Closed

bug: regression on windows since 1.7.4 #116

AntoineD opened this issue Nov 28, 2023 · 6 comments
Assignees

Comments

@AntoineD
Copy link
Contributor

Description of the bug

On windows, since version 1.7.4, the path to custom extension (docs/_docstring_inheritance.py:DocstringInheritance in below reproducer) defined in mkdocs.yml is not well handled.

To Reproduce

This can be reproduced on this project's tree : https://gitlab.com/gemseo/dev/gemseo-fmu/-/tree/develop

pip install tox
tox -e doc

Full traceback

Full traceback
ERROR   -  Error reading page 'reference/gemseo_fmu/index.md': Extension module 'C' could not be found
Traceback (most recent call last):
  File "C:\Users\XXX\gemseo-fmu\gemseo-fmu\.tox\doc\lib\site-packages\griffe\extensions\base.py", line 427, in _load_extension
    ext_object = dynamic_import(import_path)
  File "C:\Users\XXX\gemseo-fmu\gemseo-fmu\.tox\doc\lib\site-packages\griffe\importer.py", line 61, in dynamic_import
    module = import_module(module_path)
  File "C:\Python39\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'C'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\XXX\gemseo-fmu\gemseo-fmu\.tox\doc\Scripts\mkdocs.EXE\__main__.py", line 7, in <module>
  File "C:\Users\XXX\gemseo-fmu\gemseo-fmu\.tox\doc\lib\site-packages\click\core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\XXX\gemseo-fmu\gemseo-fmu\.tox\doc\lib\site-packages\click\core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "C:\Users\XXX\gemseo-fmu\gemseo-fmu\.tox\doc\lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Users\XXX\gemseo-fmu\gemseo-fmu\.tox\doc\lib\site-packages\click\core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\XXX\gemseo-fmu\gemseo-fmu\.tox\doc\lib\site-packages\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "C:\Users\XXX\gemseo-fmu\gemseo-fmu\.tox\doc\lib\site-packages\mkdocs\__main__.py", line 286, in build_command
    build.build(cfg, dirty=not clean)
  File "C:\Users\XXX\gemseo-fmu\gemseo-fmu\.tox\doc\lib\site-packages\mkdocs\commands\build.py", line 322, in build
    _populate_page(file.page, config, files, dirty)
  File "C:\Users\XXX\gemseo-fmu\gemseo-fmu\.tox\doc\lib\site-packages\mkdocs\commands\build.py", line 175, in _populate_page
    page.render(config, files)
  File "C:\Users\XXX\gemseo-fmu\gemseo-fmu\.tox\doc\lib\site-packages\mkdocs\structure\pages.py", line 271, in render
    self.content = md.convert(self.markdown)
  File "C:\Users\XXX\gemseo-fmu\gemseo-fmu\.tox\doc\lib\site-packages\markdown\core.py", line 357, in convert
    root = self.parser.parseDocument(self.lines).getroot()
  File "C:\Users\XXX\gemseo-fmu\gemseo-fmu\.tox\doc\lib\site-packages\markdown\blockparser.py", line 117, in parseDocument
    self.parseChunk(self.root, '\n'.join(lines))
  File "C:\Users\XXX\gemseo-fmu\gemseo-fmu\.tox\doc\lib\site-packages\markdown\blockparser.py", line 136, in parseChunk
    self.parseBlocks(parent, text.split('\n\n'))
  File "C:\Users\XXX\gemseo-fmu\gemseo-fmu\.tox\doc\lib\site-packages\markdown\blockparser.py", line 158, in parseBlocks
    if processor.run(parent, blocks) is not False:
  File "C:\Users\XXX\gemseo-fmu\gemseo-fmu\.tox\doc\lib\site-packages\mkdocstrings\extension.py", line 124, in run
    html, handler, data = self._process_block(identifier, block, heading_level)
  File "C:\Users\XXX\gemseo-fmu\gemseo-fmu\.tox\doc\lib\site-packages\mkdocstrings\extension.py", line 206, in _process_block
    data: CollectorItem = handler.collect(identifier, options)
  File "C:\Users\XXX\gemseo-fmu\gemseo-fmu\.tox\doc\lib\site-packages\mkdocstrings_handlers\python\handler.py", line 270, in collect
    extensions=load_extensions(extensions),
  File "C:\Users\XXX\gemseo-fmu\gemseo-fmu\.tox\doc\lib\site-packages\griffe\extensions\base.py", line 467, in load_extensions
    ext = _load_extension(extension)
  File "C:\Users\XXX\gemseo-fmu\gemseo-fmu\.tox\doc\lib\site-packages\griffe\extensions\base.py", line 429, in _load_extension
    raise ExtensionNotLoadedError(f"Extension module '{import_path}' could not be found") from error
griffe.exceptions.ExtensionNotLoadedError: Extension module 'C' could not be found

Expected behavior

No error like on linux.

Environment information

$ python -m mkdocstrings_handlers.python.debug
- __System__: Windows-10-10.0.17763-SP0
- __Python__: cpython 3.9.13
- __Environment variables__:
- __Installed packages__:
  - `mkdocs` v1.5.3
  - `mkdocstrings` v0.24.0
  - `mkdocstrings-python` v1.7.4
  - `griffe` v0.38.0
@pawamoy
Copy link
Member

pawamoy commented Nov 30, 2023

Thanks for the report, looking at it right now.

@pawamoy
Copy link
Member

pawamoy commented Nov 30, 2023

I can't reproduce locally since I don't have Windows, so I'll try and guess what's wrong 🤔

@pawamoy
Copy link
Member

pawamoy commented Nov 30, 2023

Ah, got it. Since we normalize paths and make them absolute, we end up with an extension path looking like C:/path/to/docs/_docstring_inheritance.py:DocstringInheritance, and we split on the first colon to separate the path from the class. It's a bug in Griffe: we'll have to handle absolute paths on Windows 🪟

pawamoy added a commit to mkdocstrings/griffe that referenced this issue Nov 30, 2023
@pawamoy
Copy link
Member

pawamoy commented Nov 30, 2023

Could you try again with Griffe installed from main branch? Activate tox's doc env and pip install git+https://github.com/mkdocstrings/griffe (or temporarily modify your requirements/doc.txt file).

@AntoineD
Copy link
Contributor Author

AntoineD commented Dec 4, 2023

Could you try again with Griffe installed from main branch? Activate tox's doc env and pip install git+https://github.com/mkdocstrings/griffe (or temporarily modify your requirements/doc.txt file).

This fixes the issue, thank you very much!

@pawamoy
Copy link
Member

pawamoy commented Dec 4, 2023

Great, thanks! Will release today 🙂

@pawamoy pawamoy closed this as completed Dec 4, 2023
clrpackages pushed a commit to clearlinux-pkgs/pypi-griffe that referenced this issue Dec 20, 2023
…ion 0.38.1

commit 0a370bf38aef23e98bb8c326b84e96aa710cba2c
Author: Timothée Mazzucotelli <[email protected]>
Date:   Wed Dec 6 11:37:23 2023 +0100

    chore: Prepare release 0.38.1

commit 4e67d8fa5f0e9f23c1df2e1d772fc0f1e4e6c2e0
Author: Timothée Mazzucotelli <[email protected]>
Date:   Thu Nov 30 18:36:42 2023 +0100

    fix: Support absolute Windows paths for extensions

    Issue mkdocstrings-python#116: mkdocstrings/python#116
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants