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

[Enhance] Call register_all_modules in Registry.get() #541

Merged
merged 7 commits into from
Oct 24, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion mmengine/registry/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def switch_scope_and_registry(self, scope: str) -> Generator:
if scope_name in PKG2PROJECT:
try:
module = import_module(f'{scope_name}.utils')
module.register_all_modules() # type: ignore
module.register_all_modules(False) # type: ignore
except ImportError as e:
raise e
HAOCHENYE marked this conversation as resolved.
Show resolved Hide resolved
root = self._get_root_registry()
Expand Down Expand Up @@ -347,6 +347,14 @@ def get(self, key: str) -> Optional[Type]:
break
parent = parent.parent
else:
try:
module = import_module(f'{scope_name}.utils')
HAOCHENYE marked this conversation as resolved.
Show resolved Hide resolved
module.register_all_modules(False) # type: ignore
except ImportError:
print_log(f'{scope_name} is not a package of OpenMMLab, '
'and its modules will not be registered. If you '
f'want to use modules defined in {scope_name}, '
f'please import corresponding modules firstly.')
HAOCHENYE marked this conversation as resolved.
Show resolved Hide resolved
# get from self._children
if scope in self._children:
obj_cls = self._children[scope].get(real_key)
Expand Down