mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-10 05:51:52 +08:00
Minor improvements to stubtest_third_party.py (#10605)
(1) Give a nicer error message if you try to run stubtest on non-existent stubs. (2) Print the Python version to the terminal if there's an error, as well as the output of pip freeze.
This commit is contained in:
@@ -20,6 +20,7 @@ from packaging.version import Version
|
||||
from utils import cache
|
||||
|
||||
__all__ = [
|
||||
"NoSuchStubError",
|
||||
"StubMetadata",
|
||||
"PackageDependencies",
|
||||
"StubtestSettings",
|
||||
@@ -160,6 +161,10 @@ _KNOWN_METADATA_TOOL_FIELDS: Final = {
|
||||
_DIST_NAME_RE: Final = re.compile(r"^[a-z0-9]([a-z0-9._-]*[a-z0-9])?$", re.IGNORECASE)
|
||||
|
||||
|
||||
class NoSuchStubError(ValueError):
|
||||
"""Raise NoSuchStubError to indicate that a stubs/{distribution} directory doesn't exist"""
|
||||
|
||||
|
||||
@cache
|
||||
def read_metadata(distribution: str) -> StubMetadata:
|
||||
"""Return an object describing the metadata of a stub as given in the METADATA.toml file.
|
||||
@@ -169,8 +174,11 @@ def read_metadata(distribution: str) -> StubMetadata:
|
||||
Use `read_dependencies` if you need to parse the dependencies
|
||||
given in the `requires` field, for example.
|
||||
"""
|
||||
with Path("stubs", distribution, "METADATA.toml").open("rb") as f:
|
||||
data: dict[str, object] = tomli.load(f)
|
||||
try:
|
||||
with Path("stubs", distribution, "METADATA.toml").open("rb") as f:
|
||||
data: dict[str, object] = tomli.load(f)
|
||||
except FileNotFoundError:
|
||||
raise NoSuchStubError(f"Typeshed has no stubs for {distribution!r}!") from None
|
||||
|
||||
unknown_metadata_fields = data.keys() - _KNOWN_METADATA_FIELDS
|
||||
assert not unknown_metadata_fields, f"Unexpected keys in METADATA.toml for {distribution!r}: {unknown_metadata_fields}"
|
||||
|
||||
Reference in New Issue
Block a user