From 6a571949000a3d2910990337f96751c0cac7e815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Fri, 23 Sep 2022 19:26:34 +0200 Subject: [PATCH] fix: Don't crash on unsupported module names (containing dots) Instead, log a debug message. Issue #94: https://github.com/mkdocstrings/griffe/issues/94 --- src/griffe/loader.py | 3 +++ tests/test_loader.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/griffe/loader.py b/src/griffe/loader.py index d540a4d2..24bc7371 100644 --- a/src/griffe/loader.py +++ b/src/griffe/loader.py @@ -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( diff --git a/tests/test_loader.py b/tests/test_loader.py index 565a43a3..0ab9eee9 100644 --- a/tests/test_loader.py +++ b/tests/test_loader.py @@ -1,5 +1,6 @@ """Tests for the `loader` module.""" +import logging from textwrap import dedent from griffe.expressions import Name @@ -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)