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] Enhance the error catching in registry #1010

Merged
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
27 changes: 12 additions & 15 deletions mmengine/registry/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ def import_from_location(self) -> None:
level=logging.WARNING)
try:
module = import_module(f'{self.scope}.utils')
module.register_all_modules(False) # type: ignore
except (ImportError, AttributeError, ModuleNotFoundError):
if self.scope in MODULE2PACKAGE:
print_log(
Expand All @@ -366,22 +365,20 @@ def import_from_location(self) -> None:
'have registered the module manually.',
logger='current',
level=logging.WARNING)
else:
# The import errors triggered during the registration
# may be more complex, here just throwing
# the error to avoid causing more implicit registry errors
# like `xxx`` not found in `yyy` registry.
module.register_all_modules(False) # type: ignore

for loc in self._locations:
try:
import_module(loc)
print_log(
f"Modules of {self.scope}'s {self.name} registry have "
f'been automatically imported from {loc}',
logger='current',
level=logging.DEBUG)
except (ImportError, AttributeError, ModuleNotFoundError):
print_log(
f'Failed to import {loc}, please check the '
f'location of the registry {self.name} is '
'correct.',
logger='current',
level=logging.WARNING)
import_module(loc)
print_log(
f"Modules of {self.scope}'s {self.name} registry have "
f'been automatically imported from {loc}',
logger='current',
level=logging.DEBUG)
self._imported = True

def get(self, key: str) -> Optional[Type]:
Expand Down