diff --git a/app/appstate.py b/app/appstate.py index 6530e30..a9a0e12 100644 --- a/app/appstate.py +++ b/app/appstate.py @@ -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) diff --git a/app/fetch/pypi.py b/app/fetch/pypi.py index 1826251..1aa043b 100644 --- a/app/fetch/pypi.py +++ b/app/fetch/pypi.py @@ -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)