-
Notifications
You must be signed in to change notification settings - Fork 11
/
pyre_runner.py
executable file
·62 lines (58 loc) · 1.83 KB
/
pyre_runner.py
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
#!/usr/bin/env python
"""
Run a one-time pyre static analysis check without needing a .pyre_configuration
Gets the paths dynamically so it can be used in tox and GitHub CI
"""
import os
import sys
import time
import mock
me = os.path.basename(__file__) + ":"
pyre_typesched = os.environ.get("PYRE_TYPESHED", None)
if pyre_typesched and os.path.exists(pyre_typesched + "/stdlib/os/path.pyi"):
print("Using {env:PYRE_TYPESHED}:", pyre_typesched)
else:
pyre_typesched = sys.path[-1] + "/mypy/typeshed"
if os.path.exists(pyre_typesched + "/stdlib/os/path.pyi"):
print("Using python_lib:", pyre_typesched)
else:
pyre_typesched = "/tmp/typeshed"
if os.path.exists(pyre_typesched + "/stdlib/os/path.pyi"):
print("Using:", pyre_typesched)
else:
clone = "git clone --depth 1 https://github.com/python/typeshed "
print(me, "Falling back to:", clone + pyre_typesched)
ret = os.system(clone + pyre_typesched)
if ret or not os.path.exists(pyre_typesched + "/stdlib/os/path.pyi"):
print(me, "Could not find or clone typeshed, giving up.")
sys.exit(0)
command = (
"pyre",
"--source-directory",
"xcp",
"--source-directory",
"tests",
"--search-path",
"stubs",
"--search-path",
".",
"--search-path",
os.path.dirname(mock.__file__),
"--typeshed",
pyre_typesched,
"check",
)
cmd = " ".join(command)
print(me, "Running:", cmd)
start_time = time.time()
ret = os.system(cmd)
duration = time.time() - start_time
r = os.waitstatus_to_exitcode(ret) # type: ignore[module-addr] # newer versions have it
if r == 0:
print(me, f"OK pyre took: {duration:.1f}s")
else:
print(me, "Ran:", cmd)
print(me, "exit code:", r)
if os.environ.get("ACT", None):
time.sleep(10)
sys.exit(r)