Skip to content

Commit

Permalink
fix: Don't crash on unsupported module names (containing dots)
Browse files Browse the repository at this point in the history
Instead, log a debug message.

Issue #94: #94
  • Loading branch information
pawamoy committed Sep 23, 2022
1 parent edd4b6d commit 6a57194
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/griffe/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ def _load_submodule(self, module: Module, subparts: tuple[str, ...], subpath: Pa
)
except LoadingError as error: # noqa: WPS440
logger.debug(str(error))
except KeyError:
if "." in subparts[-1]:
logger.debug(f"Skip {subpath}, dots in filenames are not supported")

def _create_module(self, module_name: str, module_path: Path | list[Path]) -> Module:
return Module(
Expand Down
14 changes: 14 additions & 0 deletions tests/test_loader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Tests for the `loader` module."""

import logging
from textwrap import dedent

from griffe.expressions import Name
Expand Down Expand Up @@ -250,3 +251,16 @@ def test_unsupported_item_in_all(caplog):
loader = GriffeLoader(search_paths=[tmp_folder.tmpdir])
loader.expand_exports(loader.load_module("package"))
assert any(item_name in record.message and record.levelname == "WARNING" for record in caplog.records)


def test_skip_modules_with_dots_in_filename(caplog):
"""Check that modules with dots in their filenames are skipped.
Parameters:
caplog: Pytest fixture to capture logs.
"""
caplog.set_level(logging.DEBUG)
with temporary_pypackage("package", ["gunicorn.conf.py"]) as tmp_folder:
loader = GriffeLoader(search_paths=[tmp_folder.tmpdir])
loader.load_module("package")
assert any("gunicorn.conf.py" in record.message and record.levelname == "DEBUG" for record in caplog.records)

0 comments on commit 6a57194

Please sign in to comment.