From 9b369e743037553312a06f8e72a64525124b62ab Mon Sep 17 00:00:00 2001 From: ice-tong Date: Wed, 6 Jul 2022 11:56:54 +0800 Subject: [PATCH] feat(mim install): prompt the built version of mmcv-full. --- mim/commands/install.py | 12 +++++++++++- mim/utils/__init__.py | 2 ++ mim/utils/utils.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/mim/commands/install.py b/mim/commands/install.py index 265c72f..7ceea4b 100644 --- a/mim/commands/install.py +++ b/mim/commands/install.py @@ -16,6 +16,7 @@ PKG2PROJECT, WHEEL_URL, echo_warning, + get_all_wheel_version, get_torch_cuda_version, ) @@ -95,7 +96,16 @@ def install( importlib.reload(pip._vendor.pkg_resources) # add mmcv-full find links by default - install_args += ['-f', get_mmcv_full_find_link()] + mmcv_full_find_link = get_mmcv_full_find_link() + install_args += ['-f', mmcv_full_find_link] + + try: + # Get and prompt the built version of mmcv-full. + all_built_versions = get_all_wheel_version(mmcv_full_find_link) + click.echo('The mmcv-full built package version that satisfies the ' + f'current environment: {all_built_versions}.') + except: # noqa: E722 + pass index_url_opt_names = ['-i', '--index-url', '--pypi-url'] if any([opt_name in install_args for opt_name in index_url_opt_names]): diff --git a/mim/utils/__init__.py b/mim/utils/__init__.py index a45f2af..1499d12 100644 --- a/mim/utils/__init__.py +++ b/mim/utils/__init__.py @@ -22,6 +22,7 @@ ensure_installation, exit_with_error, extract_tar, + get_all_wheel_version, get_config, get_content_from_url, get_github_url, @@ -88,4 +89,5 @@ 'parse_home_page', 'ensure_installation', 'rich_progress_bar', + 'get_all_wheel_version', ] diff --git a/mim/utils/utils.py b/mim/utils/utils.py index 8877b47..7252fc3 100644 --- a/mim/utils/utils.py +++ b/mim/utils/utils.py @@ -554,3 +554,32 @@ def module_full_name(abbr: str) -> str: elif abbr in names or is_installed(abbr): return abbr return '' + + +def get_all_wheel_version(index_page_url: str): + """Get all wheel version from the given index page url. + + Args: + index_page_url (str): The index page url. + + Returns: + list: A list of all version of wheel in this page. + """ + response = get_content_from_url(index_page_url, timeout=5) + anchors = re.findall(r'', response.text) + + wheel_file_re = re.compile( + r"""^(?P(?P.+?)-(?P.*?)) + ((-(?P\d[^-]*?))?-(?P.+?)-(?P.+?)-(?P.+?) + \.whl|\.dist-info)$""", + re.VERBOSE, + ) + + all_versions = set() + for anchor in anchors: + wheel_info = wheel_file_re.match(anchor.split('/')[-1]) + if wheel_info: + # TODO: check valid tags (pyversions, abis, plat) + all_versions.add(wheel_info.group('ver').replace('_', '-')) + + return sorted(all_versions, key=parse_version)