aboutsummaryrefslogtreecommitdiff
path: root/run_mypy.py
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2022-10-22 23:39:50 -0400
committerEli Schwartz <eschwartz@archlinux.org>2022-10-24 00:37:51 -0400
commit4e374d5cefd25dfa0de8debf0c53e8c6f74380d9 (patch)
treecc010b433a75edc860b9e1b81f8113d87839a591 /run_mypy.py
parent4c2b64188d574af79f4e949078a352e39710ed68 (diff)
downloadmeson-4e374d5cefd25dfa0de8debf0c53e8c6f74380d9.zip
meson-4e374d5cefd25dfa0de8debf0c53e8c6f74380d9.tar.gz
meson-4e374d5cefd25dfa0de8debf0c53e8c6f74380d9.tar.bz2
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.
Diffstat (limited to 'run_mypy.py')
-rwxr-xr-xrun_mypy.py51
1 files changed, 36 insertions, 15 deletions
diff --git a/run_mypy.py b/run_mypy.py
index 6fd0453..ba8211e 100755
--- a/run_mypy.py
+++ b/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())