Skip to content

Commit

Permalink
feat(mim install): prompt the built version of mmcv-full.
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-tong committed Jul 6, 2022
1 parent c869f73 commit 9b369e7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
12 changes: 11 additions & 1 deletion mim/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
PKG2PROJECT,
WHEEL_URL,
echo_warning,
get_all_wheel_version,
get_torch_cuda_version,
)

Expand Down Expand Up @@ -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]):
Expand Down
2 changes: 2 additions & 0 deletions mim/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
ensure_installation,
exit_with_error,
extract_tar,
get_all_wheel_version,
get_config,
get_content_from_url,
get_github_url,
Expand Down Expand Up @@ -88,4 +89,5 @@
'parse_home_page',
'ensure_installation',
'rich_progress_bar',
'get_all_wheel_version',
]
29 changes: 29 additions & 0 deletions mim/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'<a href="(.*?)">', response.text)

wheel_file_re = re.compile(
r"""^(?P<namever>(?P<name>.+?)-(?P<ver>.*?))
((-(?P<build>\d[^-]*?))?-(?P<pyver>.+?)-(?P<abi>.+?)-(?P<plat>.+?)
\.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)

0 comments on commit 9b369e7

Please sign in to comment.