Skip to content

Commit c5d6faa

Browse files
fix: don't import package if __init__ is an extension
1 parent 65d9037 commit c5d6faa

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

monty/utils/extensions.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ def walk_extensions() -> Generator[tuple[str, "ExtMetadata"], None, None]:
2828
def on_error(name: str) -> NoReturn:
2929
raise ImportError(name=name) # pragma: no cover
3030

31+
skip_modules: set[str] = set()
32+
3133
for module in pkgutil.walk_packages(exts.__path__, f"{exts.__name__}.", onerror=on_error):
32-
if unqualify(module.name).startswith("_"):
34+
if unqualify(module.name).startswith("_") or module.name in skip_modules:
3335
# Ignore module/package names starting with an underscore.
3436
continue
3537

@@ -38,6 +40,11 @@ def on_error(name: str) -> NoReturn:
3840
# If it lacks a setup function, it's not an extension.
3941
continue
4042

43+
# This check only excludes init files which add an extension.
44+
if module.name.endswith(".__init__"):
45+
# Add all submodules to skip list to avoid re-processing.
46+
skip_modules.add(module.name)
47+
4148
ext_metadata = getattr(imported, "EXT_METADATA", None)
4249
if ext_metadata is not None:
4350
if not isinstance(ext_metadata, ExtMetadata):

0 commit comments

Comments
 (0)