|
22 | 22 | import tomli |
23 | 23 | from packaging.requirements import Requirement |
24 | 24 |
|
25 | | -from ts_utils.metadata import PackageDependencies, get_recursive_requirements, read_metadata |
| 25 | +from ts_utils.metadata import PackageDependencies, get_recursive_requirements, metadata_path, read_metadata |
| 26 | +from ts_utils.paths import STDLIB_PATH, STUBS_PATH, TESTS_DIR, TS_BASE_PATH, distribution_path |
26 | 27 | from ts_utils.utils import ( |
27 | 28 | PYTHON_VERSION, |
28 | | - STDLIB_PATH, |
29 | | - TESTS_DIR, |
30 | 29 | colored, |
31 | 30 | get_gitignore_spec, |
32 | 31 | get_mypy_req, |
|
47 | 46 |
|
48 | 47 | SUPPORTED_VERSIONS = ["3.13", "3.12", "3.11", "3.10", "3.9", "3.8"] |
49 | 48 | SUPPORTED_PLATFORMS = ("linux", "win32", "darwin") |
50 | | -DIRECTORIES_TO_TEST = [Path("stdlib"), Path("stubs")] |
| 49 | +DIRECTORIES_TO_TEST = [STDLIB_PATH, STUBS_PATH] |
51 | 50 |
|
52 | 51 | VersionString: TypeAlias = Annotated[str, "Must be one of the entries in SUPPORTED_VERSIONS"] |
53 | 52 | Platform: TypeAlias = Annotated[str, "Must be one of the entries in SUPPORTED_PLATFORMS"] |
@@ -170,7 +169,7 @@ class MypyDistConf(NamedTuple): |
170 | 169 |
|
171 | 170 |
|
172 | 171 | def add_configuration(configurations: list[MypyDistConf], distribution: str) -> None: |
173 | | - with Path("stubs", distribution, "METADATA.toml").open("rb") as f: |
| 172 | + with metadata_path(distribution).open("rb") as f: |
174 | 173 | data = tomli.load(f) |
175 | 174 |
|
176 | 175 | # TODO: This could be added to ts_utils.metadata, but is currently unused |
@@ -229,7 +228,7 @@ def run_mypy( |
229 | 228 | "--platform", |
230 | 229 | args.platform, |
231 | 230 | "--custom-typeshed-dir", |
232 | | - str(Path(__file__).parent.parent), |
| 231 | + str(TS_BASE_PATH), |
233 | 232 | "--strict", |
234 | 233 | # Stub completion is checked by pyright (--allow-*-defs) |
235 | 234 | "--allow-untyped-defs", |
@@ -283,7 +282,7 @@ def add_third_party_files( |
283 | 282 | return |
284 | 283 | seen_dists.add(distribution) |
285 | 284 | seen_dists.update(r.name for r in typeshed_reqs) |
286 | | - root = Path("stubs", distribution) |
| 285 | + root = distribution_path(distribution) |
287 | 286 | for name in os.listdir(root): |
288 | 287 | if name.startswith("."): |
289 | 288 | continue |
@@ -319,7 +318,7 @@ def test_third_party_distribution( |
319 | 318 | print_error("no files found") |
320 | 319 | sys.exit(1) |
321 | 320 |
|
322 | | - mypypath = os.pathsep.join(str(Path("stubs", dist)) for dist in seen_dists) |
| 321 | + mypypath = os.pathsep.join(str(distribution_path(dist)) for dist in seen_dists) |
323 | 322 | if args.verbose: |
324 | 323 | print(colored(f"\nMYPYPATH={mypypath}", "blue")) |
325 | 324 | result = run_mypy( |
@@ -516,16 +515,12 @@ def test_third_party_stubs(args: TestConfig, tempdir: Path) -> TestSummary: |
516 | 515 | distributions_to_check: dict[str, PackageDependencies] = {} |
517 | 516 |
|
518 | 517 | for distribution in sorted(os.listdir("stubs")): |
519 | | - distribution_path = Path("stubs", distribution) |
| 518 | + dist_path = distribution_path(distribution) |
520 | 519 |
|
521 | | - if spec_matches_path(gitignore_spec, distribution_path): |
| 520 | + if spec_matches_path(gitignore_spec, dist_path): |
522 | 521 | continue |
523 | 522 |
|
524 | | - if ( |
525 | | - distribution_path in args.filter |
526 | | - or Path("stubs") in args.filter |
527 | | - or any(distribution_path in path.parents for path in args.filter) |
528 | | - ): |
| 523 | + if dist_path in args.filter or STUBS_PATH in args.filter or any(dist_path in path.parents for path in args.filter): |
529 | 524 | metadata = read_metadata(distribution) |
530 | 525 | if not metadata.requires_python.contains(PYTHON_VERSION): |
531 | 526 | msg = ( |
|
0 commit comments