[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 17/17] iotests/linters: check mypy files all at once
From: |
John Snow |
Subject: |
[PATCH v2 17/17] iotests/linters: check mypy files all at once |
Date: |
Tue, 20 Jul 2021 13:33:36 -0400 |
We can circumvent the '__main__' redefinition problem by passing
--scripts-are-modules. Take mypy out of the loop per-filename and check
everything in one go: it's quite a bit faster.
Signed-off-by: John Snow <jsnow@redhat.com>
---
tests/qemu-iotests/linters.py | 56 ++++++++++++++++-------------------
1 file changed, 26 insertions(+), 30 deletions(-)
diff --git a/tests/qemu-iotests/linters.py b/tests/qemu-iotests/linters.py
index 242cb9c3e69..b95425e81aa 100755
--- a/tests/qemu-iotests/linters.py
+++ b/tests/qemu-iotests/linters.py
@@ -86,37 +86,33 @@ def run_linters(
print('=== mypy ===')
sys.stdout.flush()
- # We have to call mypy separately for each file. Otherwise, it
- # will interpret all given files as belonging together (i.e., they
- # may not both define the same classes, etc.; most notably, they
- # must not both define the __main__ module).
- for filename in files:
- p = subprocess.run(
- (
- 'python3', '-m', 'mypy',
- '--warn-unused-configs',
- '--disallow-subclassing-any',
- '--disallow-any-generics',
- '--disallow-incomplete-defs',
- '--disallow-untyped-decorators',
- '--no-implicit-optional',
- '--warn-redundant-casts',
- '--warn-unused-ignores',
- '--no-implicit-reexport',
- '--namespace-packages',
- filename,
- ),
- cwd=directory,
- env=env,
- check=False,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT,
- universal_newlines=True
- )
+ p = subprocess.run(
+ (
+ 'python3', '-m', 'mypy',
+ '--warn-unused-configs',
+ '--disallow-subclassing-any',
+ '--disallow-any-generics',
+ '--disallow-incomplete-defs',
+ '--disallow-untyped-decorators',
+ '--no-implicit-optional',
+ '--warn-redundant-casts',
+ '--warn-unused-ignores',
+ '--no-implicit-reexport',
+ '--namespace-packages',
+ '--scripts-are-modules',
+ *files,
+ ),
+ cwd=directory,
+ env=env,
+ check=False,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
+ universal_newlines=True
+ )
- ret += p.returncode
- if p.returncode != 0:
- print(p.stdout)
+ ret += p.returncode
+ if p.returncode != 0:
+ print(p.stdout)
return ret
--
2.31.1
- [PATCH v2 10/17] iotests/297: Create main() function, (continued)
- [PATCH v2 10/17] iotests/297: Create main() function, John Snow, 2021/07/20
- [PATCH v2 09/17] iotests/297: Don't rely on distro-specific linter binaries, John Snow, 2021/07/20
- [PATCH v2 08/17] iotests/297: Include sub-directories when finding tests to lint, John Snow, 2021/07/20
- [PATCH v2 12/17] iotests/297: Add 'directory' argument to run_linters, John Snow, 2021/07/20
- [PATCH v2 11/17] iotests/297: Separate environment setup from test execution, John Snow, 2021/07/20
- [PATCH v2 16/17] python: Add iotest linters to test suite, John Snow, 2021/07/20
- [PATCH v2 15/17] iotests/linters: Add entry point for Python CI linters, John Snow, 2021/07/20
- [PATCH v2 13/17] iotests/297: return error code from run_linters(), John Snow, 2021/07/20
- [PATCH v2 14/17] iotests/297: split linters.py off from 297, John Snow, 2021/07/20
- [PATCH v2 17/17] iotests/linters: check mypy files all at once,
John Snow <=
- Re: [PATCH v2 00/17] python/iotests: Run iotest linters during Python CI, John Snow, 2021/07/20