Skip to content

Commit c9013d1

Browse files
jnsnowstsquad
authored andcommitted
iotests/linters: Add entry point for linting via Python CI
We need at least a tiny little shim here to join test file discovery with test invocation. This logic could conceivably be hosted somewhere in python/, but I felt it was strictly the least-rude thing to keep the test logic here in iotests/, even if this small function isn't itself an iotest. Note that we don't actually even need the executable bit here, we'll be relying on the ability to run this module as a script using Python CLI arguments. No chance it gets misunderstood as an actual iotest that way. (It's named, not in tests/, doesn't have the execute bit, and doesn't have an execution shebang.) Signed-off-by: John Snow <[email protected]> Reviewed-by: Hanna Reitz <[email protected]> Message-id: [email protected] Signed-off-by: John Snow <[email protected]>
1 parent c68b515 commit c9013d1

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/qemu-iotests/linters.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import os
1717
import re
1818
import subprocess
19+
import sys
1920
from typing import List, Mapping, Optional
2021

2122

@@ -74,3 +75,29 @@ def run_linter(
7475
stderr=subprocess.STDOUT if suppress_output else None,
7576
universal_newlines=True,
7677
)
78+
79+
80+
def main() -> None:
81+
"""
82+
Used by the Python CI system as an entry point to run these linters.
83+
"""
84+
def show_usage() -> None:
85+
print(f"Usage: {sys.argv[0]} < --mypy | --pylint >", file=sys.stderr)
86+
sys.exit(1)
87+
88+
if len(sys.argv) != 2:
89+
show_usage()
90+
91+
files = get_test_files()
92+
93+
if sys.argv[1] == '--pylint':
94+
run_linter('pylint', files)
95+
elif sys.argv[1] == '--mypy':
96+
run_linter('mypy', files)
97+
else:
98+
print(f"Unrecognized argument: '{sys.argv[1]}'", file=sys.stderr)
99+
show_usage()
100+
101+
102+
if __name__ == '__main__':
103+
main()

0 commit comments

Comments
 (0)