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

KeyError in GriffeLoader.load_module if two or more dots in python file name #94

Closed
MikhailPasechnik opened this issue Jul 19, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@MikhailPasechnik
Copy link

Describe the bug
If there is a file with name which contains more than one dot (for example gunicorn.conf.py)
GriffeLoader.load_module fails with KeyError here

https://github.com/mkdocstrings/griffe/blob/master/src/griffe/mixins.py#L82-L83

...
  File "../python3.10/site-packages/griffe/loader.py", line 407, in _load_submodule
    member_parent[subparts[-1]] = self._load_module(
  File "../python3.10/site-packages/griffe/mixins.py", line 85, in __setitem__
    self.members[parts[0]][parts[1:]] = value  # type: ignore[attr-defined]
KeyError: 'gunicorn'

To Reproduce
Steps to reproduce the behavior:

  1. create module with this structure
test/
       __init__.py
       some.thing.py
  1. Run command
python -c "import griffe.loader;griffe.loader.GriffeLoader().load_module('test')"
  1. See error
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/m/.local/share/virtualenvs/griffe-bug-j_gvc5DW/lib/python3.10/site-packages/griffe/loader.py", line 149, in load_module
    top_module = self._load_package(package, submodules=submodules)
  File "/Users/m/.local/share/virtualenvs/griffe-bug-j_gvc5DW/lib/python3.10/site-packages/griffe/loader.py", line 346, in _load_package
    top_module = self._load_module(package.name, package.path, submodules=submodules)
  File "/Users/m/.local/share/virtualenvs/griffe-bug-j_gvc5DW/lib/python3.10/site-packages/griffe/loader.py", line 362, in _load_module
    return self._load_module_path(module_name, module_path, submodules, parent)
  File "/Users/m/.local/share/virtualenvs/griffe-bug-j_gvc5DW/lib/python3.10/site-packages/griffe/loader.py", line 390, in _load_module_path
    self._load_submodules(module)
  File "/Users/m/.local/share/virtualenvs/griffe-bug-j_gvc5DW/lib/python3.10/site-packages/griffe/loader.py", line 395, in _load_submodules
    self._load_submodule(module, subparts, subpath)
  File "/Users/m/.local/share/virtualenvs/griffe-bug-j_gvc5DW/lib/python3.10/site-packages/griffe/loader.py", line 406, in _load_submodule
    member_parent[subparts[-1]] = self._load_module(
  File "/Users/m/.local/share/virtualenvs/griffe-bug-j_gvc5DW/lib/python3.10/site-packages/griffe/mixins.py", line 83, in __setitem__
    self.members[parts[0]][parts[1:]] = value  # type: ignore[attr-defined]
KeyError: 'some'

Expected behavior
Name for .py files with more then one dot symbol works

System (please complete the following information):

  • griffe version: 0.22.0
  • Python version: 3.10.1
  • OS: [Mac]

Additional context
Encountered this behavior using mkdocs with mkdocstrings and python handler to generate
documentation for project with fastapi api's with a lot of gunicorn.conf.py

@pawamoy
Copy link
Member

pawamoy commented Aug 17, 2022

Hello, thanks for the report.

Is there any benefit in naming the file gunicorn.conf.py rather than gunicorn_conf.py for example. Is it the file name expected by Gunicorn itself?

@MikhailPasechnik
Copy link
Author

Unfortunately yes:(

From the official documentation:

The third source of configuration information is an optional configuration file gunicorn.conf.py searched in the current working directory...

https://docs.gunicorn.org/en/stable/configure.html

@pawamoy pawamoy added the bug Something isn't working label Aug 18, 2022
pawamoy added a commit that referenced this issue Sep 23, 2022
@pawamoy
Copy link
Member

pawamoy commented Sep 23, 2022

I've pushed a fix that simply skip modules with dots in their names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants