|
6 | 6 | import argparse
|
7 | 7 | import concurrent.futures
|
8 | 8 | import os
|
9 |
| -import re |
10 | 9 | import subprocess
|
11 | 10 | import sys
|
12 | 11 | import tempfile
|
|
17 | 16 | from itertools import product
|
18 | 17 | from pathlib import Path
|
19 | 18 | from threading import Lock
|
20 |
| -from typing import TYPE_CHECKING, Any, NamedTuple, Tuple |
21 |
| - |
22 |
| -if TYPE_CHECKING: |
23 |
| - from _typeshed import StrPath |
24 |
| - |
| 19 | +from typing import Any, NamedTuple |
25 | 20 | from typing_extensions import Annotated, TypeAlias
|
26 | 21 |
|
27 | 22 | import tomli
|
|
30 | 25 | from _utils import (
|
31 | 26 | PYTHON_VERSION,
|
32 | 27 | TESTS_DIR,
|
33 |
| - VERSIONS_RE as VERSION_LINE_RE, |
34 | 28 | colored,
|
35 | 29 | get_gitignore_spec,
|
36 | 30 | get_mypy_req,
|
| 31 | + parse_stdlib_versions_file, |
37 | 32 | print_error,
|
38 | 33 | print_success_msg,
|
39 | 34 | spec_matches_path,
|
40 |
| - strip_comments, |
41 | 35 | venv_python,
|
42 | 36 | )
|
43 | 37 |
|
|
53 | 47 | DIRECTORIES_TO_TEST = [Path("stdlib"), Path("stubs")]
|
54 | 48 |
|
55 | 49 | VersionString: TypeAlias = Annotated[str, "Must be one of the entries in SUPPORTED_VERSIONS"]
|
56 |
| -VersionTuple: TypeAlias = Tuple[int, int] |
57 | 50 | Platform: TypeAlias = Annotated[str, "Must be one of the entries in SUPPORTED_PLATFORMS"]
|
58 | 51 |
|
59 | 52 |
|
@@ -150,31 +143,6 @@ def match(path: Path, args: TestConfig) -> bool:
|
150 | 143 | return False
|
151 | 144 |
|
152 | 145 |
|
153 |
| -def parse_versions(fname: StrPath) -> dict[str, tuple[VersionTuple, VersionTuple]]: |
154 |
| - result: dict[str, tuple[VersionTuple, VersionTuple]] = {} |
155 |
| - with open(fname, encoding="UTF-8") as f: |
156 |
| - for line in f: |
157 |
| - line = strip_comments(line) |
158 |
| - if line == "": |
159 |
| - continue |
160 |
| - m = VERSION_LINE_RE.match(line) |
161 |
| - assert m, f"invalid VERSIONS line: {line}" |
162 |
| - mod: str = m.group(1) |
163 |
| - min_version = parse_version(m.group(2)) |
164 |
| - max_version = parse_version(m.group(3)) if m.group(3) else (99, 99) |
165 |
| - result[mod] = min_version, max_version |
166 |
| - return result |
167 |
| - |
168 |
| - |
169 |
| -_VERSION_RE = re.compile(r"^([23])\.(\d+)$") |
170 |
| - |
171 |
| - |
172 |
| -def parse_version(v_str: str) -> tuple[int, int]: |
173 |
| - m = _VERSION_RE.match(v_str) |
174 |
| - assert m, f"invalid version: {v_str}" |
175 |
| - return int(m.group(1)), int(m.group(2)) |
176 |
| - |
177 |
| - |
178 | 146 | def add_files(files: list[Path], module: Path, args: TestConfig) -> None:
|
179 | 147 | """Add all files in package or module represented by 'name' located in 'root'."""
|
180 | 148 | if module.is_file() and module.suffix == ".pyi":
|
@@ -365,7 +333,7 @@ def test_third_party_distribution(
|
365 | 333 | def test_stdlib(args: TestConfig) -> TestResult:
|
366 | 334 | files: list[Path] = []
|
367 | 335 | stdlib = Path("stdlib")
|
368 |
| - supported_versions = parse_versions(stdlib / "VERSIONS") |
| 336 | + supported_versions = parse_stdlib_versions_file() |
369 | 337 | for name in os.listdir(stdlib):
|
370 | 338 | if name in ("VERSIONS", TESTS_DIR) or name.startswith("."):
|
371 | 339 | continue
|
|
0 commit comments