mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-16 00:37:10 +08:00
Support compatible version specifiers (#12771)
This commit is contained in:
@@ -17,7 +17,6 @@ from typing_extensions import Annotated, TypeGuard
|
||||
import tomli
|
||||
from packaging.requirements import Requirement
|
||||
from packaging.specifiers import Specifier
|
||||
from packaging.version import Version
|
||||
|
||||
from .utils import cache
|
||||
|
||||
@@ -141,7 +140,7 @@ class StubMetadata:
|
||||
"""
|
||||
|
||||
distribution: Annotated[str, "The name of the distribution on PyPI"]
|
||||
version: str
|
||||
version_spec: Annotated[Specifier, "Upstream versions that the stubs are compatible with"]
|
||||
requires: Annotated[list[Requirement], "The parsed requirements as listed in METADATA.toml"]
|
||||
extra_description: str | None
|
||||
stub_distribution: Annotated[str, "The name under which the distribution is uploaded to PyPI"]
|
||||
@@ -212,9 +211,12 @@ def read_metadata(distribution: str) -> StubMetadata:
|
||||
|
||||
assert "version" in data, f"Missing 'version' field in METADATA.toml for {distribution!r}"
|
||||
version = data["version"]
|
||||
assert isinstance(version, str)
|
||||
# Check that the version parses
|
||||
Version(version[:-2] if version.endswith(".*") else version)
|
||||
assert isinstance(version, str) and len(version) > 0, f"Invalid 'version' field in METADATA.toml for {distribution!r}"
|
||||
# Check that the version spec parses
|
||||
if version[0].isdigit():
|
||||
version = f"=={version}"
|
||||
version_spec = Specifier(version)
|
||||
assert version_spec.operator in {"==", "~="}, f"Invalid 'version' field in METADATA.toml for {distribution!r}"
|
||||
|
||||
requires_s: object = data.get("requires", [])
|
||||
assert isinstance(requires_s, list)
|
||||
@@ -289,7 +291,7 @@ def read_metadata(distribution: str) -> StubMetadata:
|
||||
|
||||
return StubMetadata(
|
||||
distribution=distribution,
|
||||
version=version,
|
||||
version_spec=version_spec,
|
||||
requires=requires,
|
||||
extra_description=extra_description,
|
||||
stub_distribution=stub_distribution,
|
||||
|
||||
Reference in New Issue
Block a user