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

[Feat] prompt the built version of mmcv-full #150

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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)