mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-09 05:24:52 +08:00
Centralize METADATA.toml parsing in the test suite (#9534)
This commit is contained in:
78
tests/check_consistent.py
Executable file → Normal file
78
tests/check_consistent.py
Executable file → Normal file
@@ -11,46 +11,14 @@ import sys
|
||||
import urllib.parse
|
||||
from pathlib import Path
|
||||
|
||||
import tomli
|
||||
import yaml
|
||||
from packaging.requirements import Requirement
|
||||
from packaging.specifiers import SpecifierSet
|
||||
from packaging.version import Version
|
||||
|
||||
from utils import (
|
||||
METADATA_MAPPING,
|
||||
VERSIONS_RE,
|
||||
get_all_testcase_directories,
|
||||
get_gitignore_spec,
|
||||
spec_matches_path,
|
||||
strip_comments,
|
||||
)
|
||||
from parse_metadata import read_metadata
|
||||
from utils import VERSIONS_RE, get_all_testcase_directories, get_gitignore_spec, spec_matches_path, strip_comments
|
||||
|
||||
metadata_keys = {
|
||||
"version",
|
||||
"requires",
|
||||
"extra_description",
|
||||
"stub_distribution",
|
||||
"obsolete_since",
|
||||
"no_longer_updated",
|
||||
"upload",
|
||||
"tool",
|
||||
}
|
||||
tool_keys = {
|
||||
"stubtest": {
|
||||
"skip",
|
||||
"apt_dependencies",
|
||||
"brew_dependencies",
|
||||
"choco_dependencies",
|
||||
"extras",
|
||||
"ignore_missing_stub",
|
||||
"platforms",
|
||||
}
|
||||
}
|
||||
extension_descriptions = {".pyi": "stub", ".py": ".py"}
|
||||
supported_stubtest_platforms = {"win32", "darwin", "linux"}
|
||||
|
||||
dist_name_re = re.compile(r"^[a-z0-9]([a-z0-9._-]*[a-z0-9])?$", re.IGNORECASE)
|
||||
|
||||
|
||||
def assert_consistent_filetypes(
|
||||
@@ -163,46 +131,8 @@ def _find_stdlib_modules() -> set[str]:
|
||||
|
||||
def check_metadata() -> None:
|
||||
for distribution in os.listdir("stubs"):
|
||||
with open(os.path.join("stubs", distribution, "METADATA.toml"), encoding="UTF-8") as f:
|
||||
data = tomli.loads(f.read())
|
||||
assert "version" in data, f"Missing version for {distribution}"
|
||||
version = data["version"]
|
||||
msg = f"Unsupported version {repr(version)}"
|
||||
assert isinstance(version, str), msg
|
||||
# Check that the version parses
|
||||
Version(version.removesuffix(".*"))
|
||||
for key in data:
|
||||
assert key in metadata_keys, f"Unexpected key {key} for {distribution}"
|
||||
assert isinstance(data.get("requires", []), list), f"Invalid requires value for {distribution}"
|
||||
for dep in data.get("requires", []):
|
||||
assert isinstance(dep, str), f"Invalid requirement {repr(dep)} for {distribution}"
|
||||
for space in " \t\n":
|
||||
assert space not in dep, f"For consistency, requirement should not have whitespace: {dep}"
|
||||
# Check that the requirement parses
|
||||
Requirement(dep)
|
||||
|
||||
if "stub_distribution" in data:
|
||||
assert dist_name_re.fullmatch(data["stub_distribution"]), f"Invalid 'stub_distribution' value for {distribution!r}"
|
||||
|
||||
assert isinstance(data.get("upload", True), bool), f"Invalid 'upload' value for {distribution!r}"
|
||||
|
||||
assert set(data.get("tool", [])).issubset(tool_keys.keys()), f"Unrecognised tool for {distribution}"
|
||||
for tool, tk in tool_keys.items():
|
||||
for key in data.get("tool", {}).get(tool, {}):
|
||||
assert key in tk, f"Unrecognised {tool} key {key} for {distribution}"
|
||||
|
||||
tool_stubtest = data.get("tool", {}).get("stubtest", {})
|
||||
specified_stubtest_platforms = set(tool_stubtest.get("platforms", ["linux"]))
|
||||
assert (
|
||||
specified_stubtest_platforms <= supported_stubtest_platforms
|
||||
), f"Unrecognised platforms specified: {supported_stubtest_platforms - specified_stubtest_platforms} for {distribution}"
|
||||
|
||||
# Check that only specified platforms install packages:
|
||||
for supported_plat in supported_stubtest_platforms:
|
||||
if supported_plat not in specified_stubtest_platforms:
|
||||
assert (
|
||||
METADATA_MAPPING[supported_plat] not in tool_stubtest
|
||||
), f"Installing system deps for unspecified platform {supported_plat} for {distribution}"
|
||||
# This function does various sanity checks for METADATA.toml files
|
||||
read_metadata(distribution)
|
||||
|
||||
|
||||
def get_txt_requirements() -> dict[str, SpecifierSet]:
|
||||
|
||||
Reference in New Issue
Block a user