|
9 | 9 |
|
10 | 10 | import argparse
|
11 | 11 | import os
|
12 |
| -import tempfile |
13 | 12 | import shutil
|
14 | 13 | import subprocess
|
| 14 | +import tempfile |
15 | 15 | from pathlib import Path
|
16 | 16 | from typing import TypeAlias
|
17 | 17 |
|
18 | 18 | ReturnCode: TypeAlias = int
|
19 | 19 |
|
20 | 20 |
|
21 |
| -def run_mypy_on_libregrtest(stdlib_dir: Path) -> ReturnCode: |
22 |
| - stdlib_test_dir = stdlib_dir / "test" |
| 21 | +def run_mypy_on_libregrtest(root_dir: Path) -> ReturnCode: |
| 22 | + test_dot_support_dir = root_dir / "Lib/" / "test" / "support" |
23 | 23 | # Copy `Lib/test/support/` into a tempdir and point MYPYPATH towards the tempdir,
|
24 | 24 | # so that mypy can see the classes and functions defined in `Lib/test/support/`
|
25 | 25 | with tempfile.TemporaryDirectory() as td:
|
26 | 26 | td_path = Path(td)
|
27 | 27 | (td_path / "test").mkdir()
|
28 |
| - shutil.copytree(stdlib_test_dir / "support", td_path / "test" / "support") |
| 28 | + shutil.copytree(test_dot_support_dir, td_path / "test" / "support") |
29 | 29 | mypy_command = [
|
30 | 30 | "mypy",
|
31 | 31 | "--config-file",
|
32 |
| - "libregrtest/mypy.ini", |
| 32 | + "Lib/test/libregrtest/mypy.ini", |
33 | 33 | ]
|
34 | 34 | result = subprocess.run(
|
35 |
| - mypy_command, cwd=stdlib_test_dir, env=os.environ | {"MYPYPATH": td} |
| 35 | + mypy_command, cwd=root_dir, env=os.environ | {"MYPYPATH": td} |
36 | 36 | )
|
37 | 37 | return result.returncode
|
38 | 38 |
|
39 | 39 |
|
40 | 40 | def main() -> ReturnCode:
|
41 | 41 | parser = argparse.ArgumentParser("Script to run mypy on Lib/test/regrtest/")
|
42 | 42 | parser.add_argument(
|
43 |
| - "--stdlib-dir", |
44 |
| - "-s", |
| 43 | + "--root-dir", |
| 44 | + "-r", |
45 | 45 | type=Path,
|
46 | 46 | required=True,
|
47 |
| - help="path to the Lib/ dir where the Python stdlib is located", |
| 47 | + help="path to the CPython repo root", |
48 | 48 | )
|
49 | 49 | args = parser.parse_args()
|
50 |
| - stdlib_dir = args.stdlib_dir |
51 |
| - if not (stdlib_dir.exists() and stdlib_dir.is_dir()): |
52 |
| - parser.error( |
53 |
| - "--stdlib-dir must point to a directory that exists on your filesystem!" |
54 |
| - ) |
55 |
| - return run_mypy_on_libregrtest(args.stdlib_dir) |
| 50 | + root_dir = args.root_dir |
| 51 | + test_dot_support_dir = root_dir / "Lib" / "test" / "support" |
| 52 | + if not (test_dot_support_dir.exists() and test_dot_support_dir.is_dir()): |
| 53 | + parser.error("--root-dir must point to the root of a CPython clone!") |
| 54 | + return run_mypy_on_libregrtest(root_dir) |
56 | 55 |
|
57 | 56 |
|
58 | 57 | if __name__ == "__main__":
|
|
0 commit comments