| 81 | |
| 82 | |
| 83 | def run_benchmark( |
| 84 | compiled_dir: str, check_dir: str, *, incremental: bool, code: str | None, foreign: bool | None |
| 85 | ) -> float: |
| 86 | cache_dir = os.path.join(compiled_dir, ".mypy_cache") |
| 87 | if os.path.isdir(cache_dir) and not incremental: |
| 88 | shutil.rmtree(cache_dir) |
| 89 | env = os.environ.copy() |
| 90 | env["PYTHONPATH"] = os.path.abspath(compiled_dir) |
| 91 | env["PYTHONHASHSEED"] = "1" |
| 92 | abschk = os.path.abspath(check_dir) |
| 93 | cmd = [sys.executable, "-m", "mypy"] |
| 94 | if code: |
| 95 | cmd += ["-c", code] |
| 96 | elif foreign: |
| 97 | pass |
| 98 | else: |
| 99 | cmd += ["--config-file", os.path.join(abschk, "mypy_self_check.ini")] |
| 100 | cmd += glob.glob(os.path.join(abschk, "mypy/*.py")) |
| 101 | cmd += glob.glob(os.path.join(abschk, "mypy/*/*.py")) |
| 102 | if incremental: |
| 103 | # Update a few files to force non-trivial incremental run |
| 104 | edit_python_file(os.path.join(abschk, "mypy/__main__.py")) |
| 105 | edit_python_file(os.path.join(abschk, "mypy/test/testcheck.py")) |
| 106 | t0 = time.time() |
| 107 | # Ignore errors, since some commits being measured may generate additional errors. |
| 108 | if foreign: |
| 109 | subprocess.run(cmd, cwd=check_dir, env=env) |
| 110 | else: |
| 111 | subprocess.run(cmd, cwd=compiled_dir, env=env) |
| 112 | return time.time() - t0 |
| 113 | |
| 114 | |
| 115 | def main() -> None: |