aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mensinger <daniel@mensinger-ka.de>2020-08-28 18:01:41 +0200
committerDaniel Mensinger <daniel@mensinger-ka.de>2020-09-08 20:15:56 +0200
commitce042f318e56f94afca7b92364728e02d068b30e (patch)
tree4952d3ee4f40a33772edc01888a4cd5a2d812ee9
parentff28f3fa34bcaaeaf487e752dc371f4ea5f1cfc2 (diff)
downloadmeson-ce042f318e56f94afca7b92364728e02d068b30e.zip
meson-ce042f318e56f94afca7b92364728e02d068b30e.tar.gz
meson-ce042f318e56f94afca7b92364728e02d068b30e.tar.bz2
typing: Add run_mypy.py for easier mypy invocation
-rw-r--r--.github/workflows/lint_mypy.yml2
-rw-r--r--mesonbuild/mlog.py2
-rwxr-xr-xrun_mypy.py82
3 files changed, 84 insertions, 2 deletions
diff --git a/.github/workflows/lint_mypy.yml b/.github/workflows/lint_mypy.yml
index e1615c2..f36c9e9 100644
--- a/.github/workflows/lint_mypy.yml
+++ b/.github/workflows/lint_mypy.yml
@@ -31,4 +31,4 @@ jobs:
with:
python-version: '3.x'
- run: python -m pip install mypy
- - run: mypy --follow-imports=skip 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
+ - run: python run_mypy.py
diff --git a/mesonbuild/mlog.py b/mesonbuild/mlog.py
index 9c19427..f8707b6 100644
--- a/mesonbuild/mlog.py
+++ b/mesonbuild/mlog.py
@@ -56,7 +56,7 @@ def colorize_console() -> bool:
sys.stdout.colorize_console = _colorize_console # type: ignore[attr-defined]
return _colorize_console
-def setup_console():
+def setup_console() -> None:
# on Windows, a subprocess might call SetConsoleMode() on the console
# connected to stdout and turn off ANSI escape processing. Call this after
# running a subprocess to ensure we turn it on again.
diff --git a/run_mypy.py b/run_mypy.py
new file mode 100755
index 0000000..68fa344
--- /dev/null
+++ b/run_mypy.py
@@ -0,0 +1,82 @@
+#!/usr/bin/env python3
+
+import sys
+import subprocess
+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',
+]
+
+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',
+ # '--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()
+
+ 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())