|
11 | 11 | import urllib.parse
|
12 | 12 | from pathlib import Path
|
13 | 13 |
|
14 |
| -import tomli |
15 | 14 | import yaml
|
16 | 15 | from packaging.requirements import Requirement
|
17 | 16 | from packaging.specifiers import SpecifierSet
|
18 |
| -from packaging.version import Version |
19 |
| - |
20 |
| -from utils import ( |
21 |
| - METADATA_MAPPING, |
22 |
| - VERSIONS_RE, |
23 |
| - get_all_testcase_directories, |
24 |
| - get_gitignore_spec, |
25 |
| - spec_matches_path, |
26 |
| - strip_comments, |
27 |
| -) |
28 |
| - |
29 |
| -metadata_keys = { |
30 |
| - "version", |
31 |
| - "requires", |
32 |
| - "extra_description", |
33 |
| - "stub_distribution", |
34 |
| - "obsolete_since", |
35 |
| - "no_longer_updated", |
36 |
| - "upload", |
37 |
| - "tool", |
38 |
| -} |
39 |
| -tool_keys = { |
40 |
| - "stubtest": { |
41 |
| - "skip", |
42 |
| - "apt_dependencies", |
43 |
| - "brew_dependencies", |
44 |
| - "choco_dependencies", |
45 |
| - "extras", |
46 |
| - "ignore_missing_stub", |
47 |
| - "platforms", |
48 |
| - } |
49 |
| -} |
50 |
| -extension_descriptions = {".pyi": "stub", ".py": ".py"} |
51 |
| -supported_stubtest_platforms = {"win32", "darwin", "linux"} |
52 | 17 |
|
53 |
| -dist_name_re = re.compile(r"^[a-z0-9]([a-z0-9._-]*[a-z0-9])?$", re.IGNORECASE) |
| 18 | +from parse_metadata import read_metadata |
| 19 | +from utils import VERSIONS_RE, get_all_testcase_directories, get_gitignore_spec, spec_matches_path, strip_comments |
| 20 | + |
| 21 | +extension_descriptions = {".pyi": "stub", ".py": ".py"} |
54 | 22 |
|
55 | 23 |
|
56 | 24 | def assert_consistent_filetypes(
|
@@ -163,46 +131,8 @@ def _find_stdlib_modules() -> set[str]:
|
163 | 131 |
|
164 | 132 | def check_metadata() -> None:
|
165 | 133 | for distribution in os.listdir("stubs"):
|
166 |
| - with open(os.path.join("stubs", distribution, "METADATA.toml"), encoding="UTF-8") as f: |
167 |
| - data = tomli.loads(f.read()) |
168 |
| - assert "version" in data, f"Missing version for {distribution}" |
169 |
| - version = data["version"] |
170 |
| - msg = f"Unsupported version {repr(version)}" |
171 |
| - assert isinstance(version, str), msg |
172 |
| - # Check that the version parses |
173 |
| - Version(version.removesuffix(".*")) |
174 |
| - for key in data: |
175 |
| - assert key in metadata_keys, f"Unexpected key {key} for {distribution}" |
176 |
| - assert isinstance(data.get("requires", []), list), f"Invalid requires value for {distribution}" |
177 |
| - for dep in data.get("requires", []): |
178 |
| - assert isinstance(dep, str), f"Invalid requirement {repr(dep)} for {distribution}" |
179 |
| - for space in " \t\n": |
180 |
| - assert space not in dep, f"For consistency, requirement should not have whitespace: {dep}" |
181 |
| - # Check that the requirement parses |
182 |
| - Requirement(dep) |
183 |
| - |
184 |
| - if "stub_distribution" in data: |
185 |
| - assert dist_name_re.fullmatch(data["stub_distribution"]), f"Invalid 'stub_distribution' value for {distribution!r}" |
186 |
| - |
187 |
| - assert isinstance(data.get("upload", True), bool), f"Invalid 'upload' value for {distribution!r}" |
188 |
| - |
189 |
| - assert set(data.get("tool", [])).issubset(tool_keys.keys()), f"Unrecognised tool for {distribution}" |
190 |
| - for tool, tk in tool_keys.items(): |
191 |
| - for key in data.get("tool", {}).get(tool, {}): |
192 |
| - assert key in tk, f"Unrecognised {tool} key {key} for {distribution}" |
193 |
| - |
194 |
| - tool_stubtest = data.get("tool", {}).get("stubtest", {}) |
195 |
| - specified_stubtest_platforms = set(tool_stubtest.get("platforms", ["linux"])) |
196 |
| - assert ( |
197 |
| - specified_stubtest_platforms <= supported_stubtest_platforms |
198 |
| - ), f"Unrecognised platforms specified: {supported_stubtest_platforms - specified_stubtest_platforms} for {distribution}" |
199 |
| - |
200 |
| - # Check that only specified platforms install packages: |
201 |
| - for supported_plat in supported_stubtest_platforms: |
202 |
| - if supported_plat not in specified_stubtest_platforms: |
203 |
| - assert ( |
204 |
| - METADATA_MAPPING[supported_plat] not in tool_stubtest |
205 |
| - ), f"Installing system deps for unspecified platform {supported_plat} for {distribution}" |
| 134 | + # This function does various sanity checks for METADATA.toml files |
| 135 | + read_metadata(distribution) |
206 | 136 |
|
207 | 137 |
|
208 | 138 | def get_txt_requirements() -> dict[str, SpecifierSet]:
|
|
0 commit comments