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.
pull/10950/head
Eli Schwartz 2 years ago
parent 4c2b64188d
commit 4e374d5cef
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 51
      run_mypy.py

@ -11,15 +11,15 @@ from mesonbuild.mesonlib import version_compare
modules = [ modules = [
# fully typed submodules # fully typed submodules
# 'mesonbuild/ast', # 'mesonbuild/ast/',
'mesonbuild/cmake', 'mesonbuild/cmake/',
'mesonbuild/compilers', 'mesonbuild/compilers/',
'mesonbuild/dependencies', 'mesonbuild/dependencies/',
'mesonbuild/interpreter/primitives', 'mesonbuild/interpreter/primitives/',
'mesonbuild/interpreterbase', 'mesonbuild/interpreterbase/',
'mesonbuild/linkers', 'mesonbuild/linkers/',
'mesonbuild/scripts', 'mesonbuild/scripts/',
'mesonbuild/wrap', 'mesonbuild/wrap/',
# specific files # specific files
'mesonbuild/arglist.py', 'mesonbuild/arglist.py',
@ -91,6 +91,8 @@ def main() -> int:
args = [] # type: T.List[str] args = [] # type: T.List[str]
parser = argparse.ArgumentParser(description='Process some integers.') 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('-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') 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: if opts.clear:
print('\x1bc', end='', flush=True) print('\x1bc', end='', flush=True)
print('Running mypy (this can take some time) ...') to_check = [] # type: T.List[str]
p = subprocess.run( if opts.files:
[sys.executable, '-m', 'mypy'] + args + modules, for f in opts.files:
cwd=root, if f in modules:
) to_check.append(f)
return p.returncode 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__': if __name__ == '__main__':
sys.exit(main()) sys.exit(main())

Loading…
Cancel
Save