Skip to content

Commit

Permalink
[Fix] Fix error package name defined in PKG2PROJECT (#872)
Browse files Browse the repository at this point in the history
* Fix PKG2PROJECT

* Rename PKG2PROJECT to MODULE2PACKAGE

* Fix ci

* Remove unnecessary change
  • Loading branch information
HAOCHENYE committed Jan 13, 2023
1 parent 2402fb1 commit 9d3f5b2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
16 changes: 11 additions & 5 deletions mmengine/config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from mmengine.fileio import load
from mmengine.utils import check_file_exist

PKG2PROJECT = {
MODULE2PACKAGE = {
'mmcls': 'mmcls',
'mmdet': 'mmdet',
'mmdet3d': 'mmdet3d',
'mmseg': 'mmsegmentation',
'mmaction2': 'mmaction2',
'mmaction': 'mmaction2',
'mmtrack': 'mmtrack',
'mmpose': 'mmpose',
'mmedit': 'mmedit',
Expand All @@ -28,6 +28,12 @@
'mmyolo': 'mmyolo',
}

# PKG2PROJECT is not a proper name to represent the mapping between module name
# (module import from) and package name (used by pip install). Therefore,
# PKG2PROJECT will be deprecated and this alias will only be kept until
# MMEngine v1.0.0
PKG2PROJECT = MODULE2PACKAGE


def _get_cfg_metainfo(package_path: str, cfg_path: str) -> dict:
"""Get target meta information from all 'metafile.yml' defined in `mode-
Expand Down Expand Up @@ -114,9 +120,9 @@ def _get_package_and_cfg_path(cfg_path: str) -> Tuple[str, str]:
'config name, but found multiple `::` in '
f'{cfg_path}')
package, cfg_path = package_cfg
assert package in PKG2PROJECT, 'mmengine does not support to load ' \
f'{package} config.'
package = PKG2PROJECT[package]
assert package in MODULE2PACKAGE, (
f'mmengine does not support to load {package} config.')
package = MODULE2PACKAGE[package]
return package, cfg_path


Expand Down
12 changes: 6 additions & 6 deletions mmengine/registry/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from importlib import import_module
from typing import Any, Dict, Generator, List, Optional, Tuple, Type, Union

from mmengine.config.utils import PKG2PROJECT
from mmengine.config.utils import MODULE2PACKAGE
from mmengine.utils import is_seq_of
from .default_scope import DefaultScope

Expand Down Expand Up @@ -259,13 +259,13 @@ def switch_scope_and_registry(self, scope: str) -> Generator:
try:
import_module(f'{scope_name}.registry')
except (ImportError, AttributeError, ModuleNotFoundError):
if scope in PKG2PROJECT:
if scope in MODULE2PACKAGE:
print_log(
f'{scope} is not installed and its '
'modules will not be registered. If you '
'want to use modules defined in '
f'{scope}, Please install {scope} by '
f'`pip install {PKG2PROJECT[scope]}.',
f'`pip install {MODULE2PACKAGE[scope]}.',
logger='current',
level=logging.WARNING)
else:
Expand Down Expand Up @@ -311,7 +311,7 @@ def import_from_location(self) -> None:
from ..logging import print_log

# avoid BC breaking
if len(self._locations) == 0 and self.scope in PKG2PROJECT:
if len(self._locations) == 0 and self.scope in MODULE2PACKAGE:
print_log(
f'The "{self.name}" registry in {self.scope} did not '
'set import location. Fallback to call '
Expand All @@ -323,13 +323,13 @@ def import_from_location(self) -> None:
module = import_module(f'{self.scope}.utils')
module.register_all_modules(False) # type: ignore
except (ImportError, AttributeError, ModuleNotFoundError):
if self.scope in PKG2PROJECT:
if self.scope in MODULE2PACKAGE:
print_log(
f'{self.scope} is not installed and its '
'modules will not be registered. If you '
'want to use modules defined in '
f'{self.scope}, Please install {self.scope} by '
f'`pip install {PKG2PROJECT[self.scope]}.',
f'`pip install {MODULE2PACKAGE[self.scope]}.',
logger='current',
level=logging.WARNING)
else:
Expand Down

0 comments on commit 9d3f5b2

Please sign in to comment.