From 4bd70aaea7c78ef2ae81bf432f53cef8971d5870 Mon Sep 17 00:00:00 2001 From: Braden Mars Date: Mon, 28 Nov 2022 04:13:01 -0600 Subject: [PATCH] feat(stubs): impl `resolve_package_url` for micropython-stubs repo. --- micropy/stubs/repositories/micropython.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/micropy/stubs/repositories/micropython.py b/micropy/stubs/repositories/micropython.py index 66f632c3..d18ba831 100644 --- a/micropy/stubs/repositories/micropython.py +++ b/micropy/stubs/repositories/micropython.py @@ -1,20 +1,22 @@ from __future__ import annotations +from typing import TYPE_CHECKING + +from distlib.locators import locate from pydantic import Field, validator from typing_extensions import Annotated from ..manifest import StubsManifest from ..package import StubPackage +if TYPE_CHECKING: + from distlib.database import Distribution + class MicropythonStubsPackage(StubPackage): name: str version: Annotated[str, Field(alias="pkg_version")] - @property - def package_name(self) -> str: - return f"{self.name}@{self.version}" - class MicropythonStubsManifest(StubsManifest): @@ -26,4 +28,6 @@ def _get_packages(cls, v: dict[str, dict]): return list(data) def resolve_package_url(self, package: StubPackage) -> str: - pass + dist: Distribution = locate(f"{package.name} ({package.version})") + dist_url = next(i for i in dist.download_urls if "tar.gz" in i) + return dist_url