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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
#!/usr/bin/env python3
import pathlib
import subprocess
import shutil
import sys
SCRIPT = pathlib.Path(__file__).resolve()
ROOT = SCRIPT.parent
def main() -> None:
print("Checking source files ...")
success = True
for check in (mypy, flake8, black, flutter_analyze):
print(f"Checking with {check.__name__} ...")
try:
check()
print(f"OK - {check.__name__} succeeded.")
except subprocess.CalledProcessError:
success = False
if not success:
print("At least one check failed.")
sys.exit(1)
print("Finished without errors.")
def mypy() -> None:
command = [
"mypy",
"--strict",
]
for f in get_python_files():
command.append(str(f))
subprocess.run(command, shell=False, check=True)
def flake8() -> None:
command = [
"flake8",
]
for f in get_python_files():
command.append(str(f))
subprocess.run(command, shell=False, check=True)
def black() -> None:
command = [
"black",
"--check",
]
for f in get_python_files():
command.append(str(f))
subprocess.run(command, shell=False, check=True)
def get_python_files() -> tuple[pathlib.Path, ...]:
return tuple(ROOT.glob("*.py"))
def flutter_analyze() -> None:
maybe_flutter = shutil.which("flutter")
if maybe_flutter is None:
print("Could not find 'flutter' executable.")
sys.exit(1)
flutter = str(maybe_flutter)
command = [
flutter,
"analyze",
]
subprocess.run(command, cwd=ROOT, shell=False, check=True)
if __name__ == "__main__":
main()
|