From 9fe8a75cb441aad74f966aed6ee84e324791f7e7 Mon Sep 17 00:00:00 2001 From: Zaida Zhou <58739961+zhouzaida@users.noreply.github.com> Date: Wed, 28 Jul 2021 20:09:44 +0800 Subject: [PATCH] [Fix] Fix missing package directory error (#72) * [Fix] Fix missing package directory error * fix grammar * fix comment * fix comment * remove a comment for debug --- mim/commands/list.py | 24 ++++++++++++++++++++---- mim/utils/utils.py | 2 +- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/mim/commands/list.py b/mim/commands/list.py index 6fe8386..39c996d 100644 --- a/mim/commands/list.py +++ b/mim/commands/list.py @@ -52,7 +52,20 @@ def list_package(all: bool = False) -> List[Tuple[str, ...]]: if not home_page: home_page = pkg.location - installed_path = get_installed_path(pkg_name) + if pkg_name.startswith('mmcv'): + pkgs_info.append((pkg_name, pkg.version, home_page)) + continue + + try: + # `installed_path` of some packages can not be obtained like + # threadpoolctl. We can ignore those packages because + # `mim list` only need to list those packages that have + # model-index.yml or model_zoo.yml file. + # more datails at https://github.com/open-mmlab/mim/issues/71 + installed_path = get_installed_path(pkg_name) + except Exception: + continue + # rename the model_zoo.yml to model-index.yml but support both # of them for backward compatibility. In addition, model-index.yml # will be put in package/.mim in PR #68 @@ -62,7 +75,10 @@ def list_package(all: bool = False) -> List[Tuple[str, ...]]: osp.join(installed_path, '.mim', 'model_zoo.yml'), osp.join(installed_path, 'model_zoo.yml') ] - if pkg_name.startswith('mmcv') or any( - map(osp.exists, possible_metadata_paths)): - pkgs_info.append((pkg_name, pkg.version, home_page)) + for path in possible_metadata_paths: + if osp.exists(path): + pkgs_info.append((pkg_name, pkg.version, home_page)) + break + + pkgs_info.sort(key=lambda pkg_info: pkg_info[0]) return pkgs_info diff --git a/mim/utils/utils.py b/mim/utils/utils.py index 338d297..56a37c4 100644 --- a/mim/utils/utils.py +++ b/mim/utils/utils.py @@ -84,7 +84,7 @@ def parse_home_page(package: str) -> Optional[str]: """Parse home page from package metadata. Args: - pakcage (str): Package to parse home page. + package (str): Package to parse home page. """ home_page = None pkg = get_distribution(package)