Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/pypi/loader.py
Show First 20 Lines • Show All 182 Lines • ▼ Show 20 Lines | - new format sample:: | ||||
}, | }, | ||||
}], | }], | ||||
... | ... | ||||
} | } | ||||
""" | """ | ||||
sha256 = p_info.sha256 | sha256 = p_info.sha256 | ||||
for rev_id, known_artifact in known_artifacts.items(): | for rev_id, known_artifact in known_artifacts.items(): | ||||
original_sha256 = _artifact_to_sha256(known_artifact) | |||||
if sha256 == original_sha256: | |||||
return rev_id | |||||
return None | |||||
def _artifact_to_sha256(known_artifact: Dict) -> Optional[str]: | |||||
"""Returns the sha256 from a PyPI 'original_artifact' dict""" | |||||
original_artifact = known_artifact["original_artifact"] | original_artifact = known_artifact["original_artifact"] | ||||
if isinstance(original_artifact, dict): | if isinstance(original_artifact, dict): | ||||
# previous loader-pypi version stored metadata as dict | # previous loader-pypi version stored metadata as dict | ||||
original_sha256 = original_artifact["sha256"] | return original_artifact["sha256"] | ||||
if sha256 == original_sha256: | |||||
return rev_id | |||||
continue | |||||
# new pypi loader actually store metadata dict differently... | # new pypi loader actually store metadata dict differently... | ||||
assert isinstance(original_artifact, list) | assert isinstance(original_artifact, list) | ||||
# current loader-pypi stores metadata as list of dict | # current loader-pypi stores metadata as list of dict | ||||
for original_artifact in known_artifact["original_artifact"]: | if len(known_artifact["original_artifact"]) == 0: | ||||
ardumont: Why did the filtering disappeared?
I see you are aligning with the npm implementation and the… | |||||
Done Inline ActionsIt did not disappear. The filtering is done by the caller instead. vlorentz: It did not disappear. The filtering is done by the caller instead. | |||||
Not Done Inline ActionsIn the prior implementation for that loop (from line 208 of this version), prior to this diff, we iterated over all values. ardumont: In the prior implementation for that loop (from line 208 of this version), prior to this diff… | |||||
Done Inline Actionsoh, right; the issue isn't filtering, but that I'm only returning the first element. vlorentz: oh, right; the issue isn't filtering, but that I'm only returning the first element. | |||||
Not Done Inline Actionsyes. And I'm merely pointing this "discrepancy" out. ardumont: yes.
And I'm merely pointing this "discrepancy" out.
| |||||
if sha256 == original_artifact["checksums"]["sha256"]: | |||||
return rev_id | |||||
return None | return None | ||||
elif len(known_artifact["original_artifact"]) == 1: | |||||
return original_artifact[0]["checksums"]["sha256"] | |||||
else: | |||||
raise ValueError( | |||||
f"Expected exactly one PyPI original_artifact, got " | |||||
f"{len(known_artifact['original_artifact'])}" | |||||
) | |||||
def pypi_api_url(url: str) -> str: | def pypi_api_url(url: str) -> str: | ||||
"""Compute api url from a project url | """Compute api url from a project url | ||||
Args: | Args: | ||||
url (str): PyPI instance's url (e.g: https://pypi.org/project/requests) | url (str): PyPI instance's url (e.g: https://pypi.org/project/requests) | ||||
This deals with correctly transforming the project's api url (e.g | This deals with correctly transforming the project's api url (e.g | ||||
▲ Show 20 Lines • Show All 78 Lines • Show Last 20 Lines |
Why did the filtering disappeared?
I see you are aligning with the npm implementation and the pypi one (slightly differently).
Are you sure this this is the way to go?
Why not the other around, having the filtering in both implementation instead?