Improve micropip error message when no package is found (#2562)

Show better error message when fetching metadata from PyPI fails.
Previously it just showed "Failed to Fetch"
This commit is contained in:
Gyeongjae Choi 2022-05-17 06:03:32 +09:00 committed by GitHub
parent a99f9ef172
commit ec80351b7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 1 deletions

View File

@ -85,7 +85,14 @@ else:
async def _get_pypi_json(pkgname: str, fetch_extra_kwargs: dict[str, str]):
url = f"https://pypi.org/pypi/{pkgname}/json"
return json.loads(await fetch_string(url, fetch_extra_kwargs))
try:
metadata = await fetch_string(url, fetch_extra_kwargs)
except Exception as e:
raise ValueError(
f"Can't fetch metadata for '{pkgname}' from PyPI. "
"Please make sure you have entered a correct package name."
) from e
return json.loads(metadata)
def _is_pure_python_wheel(filename: str):
@ -327,7 +334,12 @@ class _PackageManager:
raise ValueError(
f"Requested '{req}', " f"but {req.name}=={ver} is already installed"
)
<<<<<<< micropip/nopackage -- Incoming Change
metadata = await _get_pypi_json(req.name, fetch_extra_kwargs)
=======
metadata = await _get_pypi_json(req.name, transaction.fetch_extra_kwargs)
>>>>>>> main -- Current Change
try:
wheel = self.find_wheel(metadata, req)