2020-08-29 00:01:41 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
from pathlib import Path
|
2021-01-23 04:48:22 +08:00
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2020-08-29 00:01:41 +08:00
|
|
|
import typing as T
|
|
|
|
|
2021-06-11 22:58:27 +08:00
|
|
|
from mesonbuild.mesonlib import version_compare
|
|
|
|
|
2020-08-30 21:58:23 +08:00
|
|
|
modules = [
|
2020-09-27 17:15:57 +08:00
|
|
|
# fully typed submodules
|
2021-06-17 06:27:39 +08:00
|
|
|
# 'mesonbuild/ast',
|
2020-09-28 18:31:23 +08:00
|
|
|
'mesonbuild/cmake',
|
2020-09-29 05:51:09 +08:00
|
|
|
'mesonbuild/compilers',
|
2021-06-08 00:12:53 +08:00
|
|
|
'mesonbuild/dependencies',
|
2021-06-10 18:18:06 +08:00
|
|
|
'mesonbuild/interpreterbase',
|
2021-06-04 03:10:19 +08:00
|
|
|
'mesonbuild/linkers',
|
2020-09-27 17:15:57 +08:00
|
|
|
'mesonbuild/scripts',
|
|
|
|
'mesonbuild/wrap',
|
2020-08-30 21:58:23 +08:00
|
|
|
|
2020-09-27 17:15:57 +08:00
|
|
|
# specific files
|
|
|
|
'mesonbuild/arglist.py',
|
|
|
|
# 'mesonbuild/coredata.py',
|
|
|
|
'mesonbuild/envconfig.py',
|
2021-06-17 06:27:39 +08:00
|
|
|
'mesonbuild/interpreter/interpreterobjects.py',
|
2021-08-05 04:23:49 +08:00
|
|
|
'mesonbuild/interpreter/type_checking.py',
|
2020-09-27 17:15:57 +08:00
|
|
|
'mesonbuild/mcompile.py',
|
2021-02-21 01:04:01 +08:00
|
|
|
'mesonbuild/mdevenv.py',
|
2021-01-23 04:48:22 +08:00
|
|
|
'mesonbuild/mesonlib/platform.py',
|
|
|
|
'mesonbuild/mesonlib/universal.py',
|
2020-09-27 17:15:57 +08:00
|
|
|
'mesonbuild/minit.py',
|
2021-01-13 04:49:58 +08:00
|
|
|
'mesonbuild/minstall.py',
|
2020-09-27 17:15:57 +08:00
|
|
|
'mesonbuild/mintro.py',
|
|
|
|
'mesonbuild/mlog.py',
|
|
|
|
'mesonbuild/modules/fs.py',
|
2020-10-22 07:07:31 +08:00
|
|
|
'mesonbuild/modules/unstable_rust.py',
|
2021-06-02 07:33:09 +08:00
|
|
|
'mesonbuild/modules/qt.py',
|
2020-09-27 17:15:57 +08:00
|
|
|
'mesonbuild/mparser.py',
|
|
|
|
'mesonbuild/msetup.py',
|
|
|
|
'mesonbuild/mtest.py',
|
2020-11-21 03:34:28 +08:00
|
|
|
'mesonbuild/optinterpreter.py',
|
2020-10-02 04:25:16 +08:00
|
|
|
'mesonbuild/programs.py',
|
2020-08-29 00:01:41 +08:00
|
|
|
|
2021-06-23 05:16:15 +08:00
|
|
|
'run_custom_lint.py',
|
2020-09-27 17:15:57 +08:00
|
|
|
'run_mypy.py',
|
2021-06-08 18:48:33 +08:00
|
|
|
'run_project_tests.py',
|
2021-02-20 04:19:27 +08:00
|
|
|
'run_single_test.py',
|
2020-09-27 17:15:57 +08:00
|
|
|
'tools'
|
2020-08-29 00:01:41 +08:00
|
|
|
]
|
|
|
|
|
2021-01-23 04:48:22 +08:00
|
|
|
if os.name == 'posix':
|
|
|
|
modules.append('mesonbuild/mesonlib/posix.py')
|
|
|
|
elif os.name == 'nt':
|
|
|
|
modules.append('mesonbuild/mesonlib/win32.py')
|
|
|
|
|
2020-08-29 00:01:41 +08:00
|
|
|
def check_mypy() -> None:
|
2020-09-27 17:15:57 +08:00
|
|
|
try:
|
|
|
|
import mypy
|
|
|
|
except ImportError:
|
|
|
|
print('Failed import mypy')
|
|
|
|
sys.exit(1)
|
2021-06-11 22:58:27 +08:00
|
|
|
from mypy.version import __version__ as mypy_version
|
2021-06-14 12:24:45 +08:00
|
|
|
if not version_compare(mypy_version, '>=0.812'):
|
|
|
|
print('mypy >=0.812 is required, older versions report spurious errors')
|
2021-06-11 22:58:27 +08:00
|
|
|
sys.exit(1)
|
2020-08-29 00:01:41 +08:00
|
|
|
|
|
|
|
def main() -> int:
|
2020-09-27 17:15:57 +08:00
|
|
|
check_mypy()
|
2020-08-29 00:01:41 +08:00
|
|
|
|
2020-09-27 17:15:57 +08:00
|
|
|
root = Path(__file__).absolute().parent
|
|
|
|
args = [] # type: T.List[str]
|
2020-08-30 21:58:23 +08:00
|
|
|
|
2020-09-27 17:15:57 +08:00
|
|
|
parser = argparse.ArgumentParser(description='Process some integers.')
|
|
|
|
parser.add_argument('-p', '--pretty', action='store_true', help='pretty print mypy errors')
|
2020-09-27 17:21:36 +08:00
|
|
|
parser.add_argument('-C', '--clear', action='store_true', help='clear the terminal before running mypy')
|
2020-08-29 01:29:20 +08:00
|
|
|
|
2020-09-27 17:15:57 +08:00
|
|
|
opts = parser.parse_args()
|
|
|
|
if opts.pretty:
|
|
|
|
args.append('--pretty')
|
2020-08-29 01:29:20 +08:00
|
|
|
|
2020-09-27 17:21:36 +08:00
|
|
|
if opts.clear:
|
|
|
|
print('\x1bc', end='', flush=True)
|
|
|
|
|
|
|
|
print('Running mypy (this can take some time) ...')
|
2020-09-27 17:15:57 +08:00
|
|
|
p = subprocess.run(
|
|
|
|
[sys.executable, '-m', 'mypy'] + args + modules,
|
|
|
|
cwd=root,
|
|
|
|
)
|
|
|
|
return p.returncode
|
2020-08-29 00:01:41 +08:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-09-27 17:15:57 +08:00
|
|
|
sys.exit(main())
|