-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathtest__mypy_accepts_our_packages.py
More file actions
66 lines (56 loc) · 1.88 KB
/
test__mypy_accepts_our_packages.py
File metadata and controls
66 lines (56 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import pathlib
import shutil
import subprocess
import sys
import tempfile
import time
def main() -> None:
for package_name, setup_file in [
("approval_utilities", "setup.approval_utilities.py"),
("approvaltests", "setup.approvaltests.py"),
("approvaltests", "setup.approvaltests-minimal.py"),
]:
dist_dir = pathlib.Path("dist")
if dist_dir.exists():
shutil.rmtree(dist_dir)
shutil.copy2("setup/" + setup_file, "setup.py")
try:
subprocess.check_output([sys.executable, "-m", "build", "--wheel", "."])
finally:
_unlink_with_retry(pathlib.Path("setup.py"))
wheel_files = list(dist_dir.glob("*.whl"))
assert len(wheel_files) == 1, f"Expected 1 wheel, found {wheel_files}"
subprocess.check_call(
[
sys.executable,
"-m",
"pip",
"install",
"--force-reinstall",
wheel_files[0],
"--quiet",
"--no-warn-script-location",
]
)
with tempfile.TemporaryDirectory() as _temporary_directory:
temporary_directory = pathlib.Path(_temporary_directory)
test_file_path = temporary_directory / "test.py"
test_file_path.write_text(f"import {package_name}")
subprocess.check_call(
[sys.executable, "-m", "mypy", str(test_file_path)],
cwd=temporary_directory,
)
def _unlink_with_retry(
path: pathlib.Path, retries: int = 5, delay: float = 1.0
) -> None:
for attempt in range(retries):
try:
path.unlink(missing_ok=True)
return
except PermissionError:
if attempt < retries - 1:
time.sleep(delay)
else:
raise
if __name__ == "__main__":
main()