run_mypy: add extra logging and permit specifying files to check
If those files are not yet known to be typed, skip them. This makes it possible to trivially check a shortlist of files that were just changed and see if they regress our mypy coverage. Ideal for use in a git pre-commit hook.
This commit is contained in:
parent
4c2b64188d
commit
4e374d5cef
51
run_mypy.py
51
run_mypy.py
|
@ -11,15 +11,15 @@ from mesonbuild.mesonlib import version_compare
|
|||
|
||||
modules = [
|
||||
# fully typed submodules
|
||||
# 'mesonbuild/ast',
|
||||
'mesonbuild/cmake',
|
||||
'mesonbuild/compilers',
|
||||
'mesonbuild/dependencies',
|
||||
'mesonbuild/interpreter/primitives',
|
||||
'mesonbuild/interpreterbase',
|
||||
'mesonbuild/linkers',
|
||||
'mesonbuild/scripts',
|
||||
'mesonbuild/wrap',
|
||||
# 'mesonbuild/ast/',
|
||||
'mesonbuild/cmake/',
|
||||
'mesonbuild/compilers/',
|
||||
'mesonbuild/dependencies/',
|
||||
'mesonbuild/interpreter/primitives/',
|
||||
'mesonbuild/interpreterbase/',
|
||||
'mesonbuild/linkers/',
|
||||
'mesonbuild/scripts/',
|
||||
'mesonbuild/wrap/',
|
||||
|
||||
# specific files
|
||||
'mesonbuild/arglist.py',
|
||||
|
@ -91,6 +91,8 @@ def main() -> int:
|
|||
args = [] # type: T.List[str]
|
||||
|
||||
parser = argparse.ArgumentParser(description='Process some integers.')
|
||||
parser.add_argument('files', nargs='*')
|
||||
parser.add_argument('-q', '--quiet', action='store_true', help='do not print informational messages')
|
||||
parser.add_argument('-p', '--pretty', action='store_true', help='pretty print mypy errors')
|
||||
parser.add_argument('-C', '--clear', action='store_true', help='clear the terminal before running mypy')
|
||||
|
||||
|
@ -101,12 +103,31 @@ def main() -> int:
|
|||
if opts.clear:
|
||||
print('\x1bc', end='', flush=True)
|
||||
|
||||
print('Running mypy (this can take some time) ...')
|
||||
p = subprocess.run(
|
||||
[sys.executable, '-m', 'mypy'] + args + modules,
|
||||
cwd=root,
|
||||
)
|
||||
return p.returncode
|
||||
to_check = [] # type: T.List[str]
|
||||
if opts.files:
|
||||
for f in opts.files:
|
||||
if f in modules:
|
||||
to_check.append(f)
|
||||
elif any(f.startswith(i) for i in modules):
|
||||
to_check.append(f)
|
||||
else:
|
||||
if not opts.quiet:
|
||||
print(f'skipping {f!r} because it is not yet typed')
|
||||
else:
|
||||
to_check.extend(modules)
|
||||
|
||||
if to_check:
|
||||
if not opts.quiet:
|
||||
print('Running mypy (this can take some time) ...')
|
||||
p = subprocess.run(
|
||||
[sys.executable, '-m', 'mypy'] + args + to_check,
|
||||
cwd=root,
|
||||
)
|
||||
return p.returncode
|
||||
else:
|
||||
if not opts.quiet:
|
||||
print('nothing to do...')
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
|
|
Loading…
Reference in New Issue