4 # Copyright (C) 2020 Red Hat, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
28 # TODO: Empty this list!
30 '030', '040', '041', '044', '045', '055', '056', '057', '065', '093',
31 '096', '118', '124', '132', '136', '139', '147', '148', '149',
32 '151', '152', '155', '163', '165', '169', '194', '196', '199', '202',
33 '203', '205', '206', '207', '208', '210', '211', '212', '213', '216',
34 '218', '219', '222', '224', '228', '234', '235', '236', '237', '238',
35 '240', '242', '245', '246', '248', '255', '256', '257', '258', '260',
36 '262', '264', '266', '274', '277', '280', '281', '295', '296', '298',
37 '299', '302', '303', '304', '307',
38 'nbd-fault-injector.py', 'qcow2.py', 'qcow2_format.py', 'qed.py'
42 def is_python_file(filename):
43 if not os.path.isfile(filename):
46 if filename.endswith('.py'):
49 with open(filename) as f:
51 first_line = f.readline()
52 return re.match('^#!.*python', first_line) is not None
53 except UnicodeDecodeError: # Ignore binary files
58 files = [filename for filename in (set(os.listdir('.')) - set(SKIP_FILES))
59 if is_python_file(filename)]
61 iotests.logger.debug('Files to be checked:')
62 iotests.logger.debug(', '.join(sorted(files)))
64 print('=== pylint ===')
67 # Todo notes are fine, but fixme's or xxx's should probably just be
68 # fixed (in tests, at least)
69 env = os.environ.copy()
70 qemu_module_path = os.path.join(os.path.dirname(__file__),
73 env['PYTHONPATH'] += os.pathsep + qemu_module_path
75 env['PYTHONPATH'] = qemu_module_path
76 subprocess.run(('pylint-3', '--score=n', '--notes=FIXME,XXX', *files),
82 # We have to call mypy separately for each file. Otherwise, it
83 # will interpret all given files as belonging together (i.e., they
84 # may not both define the same classes, etc.; most notably, they
85 # must not both define the __main__ module).
86 env['MYPYPATH'] = env['PYTHONPATH']
87 for filename in files:
88 p = subprocess.run(('mypy',
89 '--warn-unused-configs',
90 '--disallow-subclassing-any',
91 '--disallow-any-generics',
92 '--disallow-incomplete-defs',
93 '--disallow-untyped-decorators',
94 '--no-implicit-optional',
95 '--warn-redundant-casts',
96 '--warn-unused-ignores',
97 '--no-implicit-reexport',
101 stdout=subprocess.PIPE,
102 stderr=subprocess.STDOUT,
103 universal_newlines=True)
105 if p.returncode != 0:
109 for linter in ('pylint-3', 'mypy'):
110 if shutil.which(linter) is None:
111 iotests.notrun(f'{linter} not found')
113 iotests.script_main(run_linters)