Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/migrate_extrinsic_metadata.py
Show First 20 Lines • Show All 253 Lines • ▼ Show 20 Lines | def pypi_origin_from_filename(storage, rev_id: bytes, filename: str) -> Optional[str]: | ||||
# are wrong (by far the most common case), PyPI kindly corrects them. | # are wrong (by far the most common case), PyPI kindly corrects them. | ||||
try: | try: | ||||
resp = urlopen(f"https://pypi.org/pypi/{project_name}/json/") | resp = urlopen(f"https://pypi.org/pypi/{project_name}/json/") | ||||
except HTTPError as e: | except HTTPError as e: | ||||
assert e.code == 404 | assert e.code == 404 | ||||
# nope; PyPI couldn't correct the wrong project name | # nope; PyPI couldn't correct the wrong project name | ||||
return None | return None | ||||
assert resp.code == 200, resp.code | assert resp.code == 200, resp.code | ||||
project_name = json.load(resp)["name"] | project_name = json.load(resp)["info"]["name"] | ||||
ardumont: is the info entry always there? | |||||
Done Inline ActionsI haven't found a single case where it's not. And if it happens, I want the script to crash to I can debug it, anyway vlorentz: I haven't found a single case where it's not. And if it happens, I want the script to crash to… | |||||
origin = pypi_origin_from_project_name(project_name) | origin = pypi_origin_from_project_name(project_name) | ||||
if _check_revision_in_origin(storage, origin, rev_id): | if _check_revision_in_origin(storage, origin, rev_id): | ||||
return origin | return origin | ||||
else: | else: | ||||
# The origin exists, but the revision does not belong in it. | # The origin exists, but the revision does not belong in it. | ||||
# This happens sometimes, as the filename we guessed the origin | # This happens sometimes, as the filename we guessed the origin | ||||
# from is user-provided. | # from is user-provided. | ||||
▲ Show 20 Lines • Show All 894 Lines • Show Last 20 Lines |
is the info entry always there?