Skip to content

Commit

Permalink
feat(stubs): make micropython stubs package sortable.
Browse files Browse the repository at this point in the history
Signed-off-by: Braden Mars <bradenmars@bradenmars.me>
  • Loading branch information
BradenM committed Dec 11, 2022
1 parent 9d17331 commit 49b6df0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions micropy/stubs/repositories/micropython.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from __future__ import annotations

import functools
from typing import TYPE_CHECKING

from distlib.locators import locate
from distlib.version import NormalizedVersion
from pydantic import Field, validator
from typing_extensions import Annotated

Expand All @@ -13,12 +15,20 @@
from distlib.database import Distribution


@functools.total_ordering
class MicropythonStubsPackage(StubPackage):
name: str
version: Annotated[str, Field(alias="pkg_version")]

@property
def package_version(self) -> NormalizedVersion:
return NormalizedVersion(self.version)

def __lt__(self, other: MicropythonStubsPackage) -> bool:
return self.package_version < other.package_version

def __eq__(self, other: MicropythonStubsPackage) -> bool:
return self.name == other.name and self.version == other.version


class MicropythonStubsManifest(StubsManifest[MicropythonStubsPackage]):
Expand Down

0 comments on commit 49b6df0

Please sign in to comment.