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
90
91
92
93
94
|
#!/usr/bin/env python3
import sys
import subprocess
import argparse
from pathlib import Path
import typing as T
normal_modules = [
'mesonbuild/interpreterbase.py',
'mesonbuild/mtest.py',
'mesonbuild/minit.py',
'mesonbuild/mintro.py',
'mesonbuild/mparser.py',
'mesonbuild/msetup.py',
'mesonbuild/ast',
'mesonbuild/wrap',
'tools',
'mesonbuild/modules/fs.py',
'mesonbuild/dependencies/boost.py',
'mesonbuild/dependencies/mpi.py',
'mesonbuild/dependencies/hdf5.py',
'mesonbuild/compilers/mixins/intel.py',
'mesonbuild/mlog.py',
'mesonbuild/mcompile.py',
'mesonbuild/mesonlib.py',
'mesonbuild/arglist.py',
# 'mesonbuild/envconfig.py',
]
strict_modules = [
'mesonbuild/interpreterbase.py',
'mesonbuild/mesonlib.py',
'mesonbuild/mlog.py',
'mesonbuild/ast',
'run_mypy.py',
]
normal_args = ['--follow-imports=skip']
strict_args = normal_args + [
'--warn-redundant-casts',
'--warn-unused-ignores',
'--warn-return-any',
# '--warn-unreachable',
'--disallow-untyped-calls',
'--disallow-untyped-defs',
'--disallow-incomplete-defs',
'--disallow-untyped-decorators',
'--no-implicit-optional',
'--strict-equality',
# '--disallow-any-expr',
# '--disallow-any-decorated',
# '--disallow-any-explicit',
# '--disallow-any-generics',
# '--disallow-subclassing-any',
]
def run_mypy(opts: T.List[str], modules: T.List[str]) -> int:
root = Path(__file__).absolute().parent
p = subprocess.run(
[sys.executable, '-m', 'mypy'] + opts + modules,
cwd=root,
)
return p.returncode
def check_mypy() -> None:
try:
import mypy
except ImportError:
print('Failed import mypy')
sys.exit(1)
def main() -> int:
res = 0
check_mypy()
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('-p', '--pretty', action='store_true', help='pretty print mypy errors')
args = parser.parse_args()
if args.pretty:
normal_args.append('--pretty')
strict_args.append('--pretty')
print('Running normal mypy check...')
res += run_mypy(normal_args, normal_modules)
print('\n\nRunning struct mypy check...')
res += run_mypy(strict_args, strict_modules)
return res
if __name__ == '__main__':
sys.exit(main())
|