mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-28 05:50:37 +00:00
c293ba55c5
Now, 297 is just the iotests-specific incantations and linters.py is as minimal as I can think to make it. The only remaining element in here that ought to be configuration and not code is the list of skip files, but they're still numerous enough that repeating them for mypy and pylint configurations both would be ... a hassle. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Hanna Reitz <hreitz@redhat.com> Message-id: 20211019144918.3159078-12-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
83 lines
2.1 KiB
Python
Executable File
83 lines
2.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# group: meta
|
|
#
|
|
# Copyright (C) 2020 Red Hat, Inc.
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
from typing import List
|
|
|
|
import iotests
|
|
import linters
|
|
|
|
|
|
# Looking for something?
|
|
#
|
|
# List of files to exclude from linting: linters.py
|
|
# mypy configuration: mypy.ini
|
|
# pylint configuration: pylintrc
|
|
|
|
|
|
def check_linter(linter: str) -> bool:
|
|
try:
|
|
linters.run_linter(linter, ['--version'], suppress_output=True)
|
|
except subprocess.CalledProcessError:
|
|
iotests.case_notrun(f"'{linter}' not found")
|
|
return False
|
|
return True
|
|
|
|
|
|
def test_pylint(files: List[str]) -> None:
|
|
print('=== pylint ===')
|
|
sys.stdout.flush()
|
|
|
|
if not check_linter('pylint'):
|
|
return
|
|
|
|
linters.run_linter('pylint', files)
|
|
|
|
|
|
def test_mypy(files: List[str]) -> None:
|
|
print('=== mypy ===')
|
|
sys.stdout.flush()
|
|
|
|
if not check_linter('mypy'):
|
|
return
|
|
|
|
env = os.environ.copy()
|
|
env['MYPYPATH'] = env['PYTHONPATH']
|
|
|
|
linters.run_linter('mypy', files, env=env, suppress_output=True)
|
|
|
|
|
|
def main() -> None:
|
|
files = linters.get_test_files()
|
|
|
|
iotests.logger.debug('Files to be checked:')
|
|
iotests.logger.debug(', '.join(sorted(files)))
|
|
|
|
for test in (test_pylint, test_mypy):
|
|
try:
|
|
test(files)
|
|
except subprocess.CalledProcessError as exc:
|
|
# Linter failure will be caught by diffing the IO.
|
|
if exc.output:
|
|
print(exc.output)
|
|
|
|
|
|
iotests.script_main(main)
|