Fix matching of pypi references

Now that we use purls we need to convert them to pypi project names
before looking them up.
This commit is contained in:
Christoph Reiter 2025-02-17 08:24:01 +01:00
parent 0909a67fa4
commit 2039923f25
2 changed files with 20 additions and 6 deletions

View File

@ -37,6 +37,15 @@ class ExtId(NamedTuple):
guess_name: bool
"""Guess the external package name, if none is explicitely specified"""
def get_key_from_references(self, references: dict[str, list[str | None]]) -> str | None:
"""Given the references, return the key for the external system, if available"""
if self.id in references:
for entry in references[self.id]:
if entry is not None:
return entry
return None
class ExtInfo(NamedTuple):
name: str
@ -578,11 +587,10 @@ class Source:
ext = []
for ext_id in state.ext_info_ids:
variants = []
if ext_id.id in self.pkgextra.references:
mapped = self.pkgextra.references[ext_id.id][0]
if mapped is None:
continue
variants = [mapped]
ext_key = ext_id.get_key_from_references(self.pkgextra.references)
if ext_key is not None:
variants = [ext_key]
elif ext_id.guess_name:
variants = get_realname_variants(self)

View File

@ -50,6 +50,12 @@ def extract_pypi_project_from_references(references: dict[str, list[str | None]]
return None
class PyPIExtId(ExtId):
def get_key_from_references(self, references: dict[str, list[str | None]]) -> str | None:
return extract_pypi_project_from_references(references)
async def update_pypi_versions(pkgextra: PkgExtra) -> None:
urls = PYPI_URLS
if not await check_needs_update(urls):
@ -83,4 +89,4 @@ async def update_pypi_versions(pkgextra: PkgExtra) -> None:
pypi_versions[pypi_name] = ExtInfo(
pypi_name, info["version"], oldest_timestamp, info["project_url"], {})
state.set_ext_infos(ExtId("pypi", "PyPI", False, False), pypi_versions)
state.set_ext_infos(PyPIExtId("pypi", "PyPI", False, False), pypi_versions)