8000 Fix for import_submodules by matt-gardner · Pull Request #1976 · allenai/allennlp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Fix for import_submodules #1976

Merged
merged 3 commits into from
Oct 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion allennlp/common/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,14 @@ def import_submodules(package_name: str) -> None:
# Import at top level
module = importlib.import_module(package_name)
path = getattr(module, '__path__', [])
path_string = '' if not path else path[0]

# walk_packages only finds immediate children, so need to recurse.
for _, name, _ in pkgutil.walk_packages(path):
for module_finder, name, _ in pkgutil.walk_packages(path):
# Sometimes when you import third-party libraries that are on your path,
# `pkgutil.walk_packages` returns those too, so we need to skip them.
if path_string and module_finder.path != path_string:
continue
subpackage = f"{package_name}.{name}"
import_submodules(subpackage)

Expand Down
0