Skip to content

Commit

Permalink
feat(stubs): micropy-stubs resolve package url impl, stub micropython…
Browse files Browse the repository at this point in the history
… for now.
  • Loading branch information
BradenM committed Dec 11, 2022
1 parent 8737f52 commit c832cb0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
24 changes: 20 additions & 4 deletions micropy/stubs/repositories/micropy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import annotations

from pydantic import Field, validator
from pathlib import PurePosixPath
from urllib import parse

from pydantic import Field, root_validator
from typing_extensions import Annotated

from ..manifest import StubsManifest
Expand All @@ -13,8 +16,21 @@ class MicropyStubPackage(StubPackage):


class MicropyStubsManifest(StubsManifest):
location: str
path: str
packages: list[MicropyStubPackage]

@validator("packages", pre=True)
def _get_packages(cls, v: dict[str, dict]):
return v["packages"]
@root_validator(pre=True)
def check(cls, values: dict):
pkgs = values["packages"]
if "packages" in pkgs:
values["location"] = pkgs["location"]
values["path"] = pkgs["path"]
values["packages"] = pkgs["packages"]
return values

def resolve_package_url(self, package: StubPackage) -> str:
base_path = PurePosixPath(parse.urlparse(self.location).path)
pkg_path = base_path / PurePosixPath(self.path) / PurePosixPath(package.name)
url = parse.urljoin(self.location, str(pkg_path))
return url
4 changes: 4 additions & 0 deletions micropy/stubs/repositories/micropython.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ def package_name(self) -> str:


class MicropythonStubsManifest(StubsManifest):

packages: list[MicropythonStubsPackage]

@validator("packages", pre=True)
def _get_packages(cls, v: dict[str, dict]):
data = v["data"].values()
return list(data)

def resolve_package_url(self, package: StubPackage) -> str:
pass

0 comments on commit c832cb0

Please sign in to comment.