qutebrowser/run_checks.py

114 lines
3.5 KiB
Python
Raw Normal View History

2014-01-29 04:07:27 +01:00
""" Run different codecheckers over a codebase.
2014-02-04 22:10:27 +01:00
Runs flake8, pylint and a CRLF/whitespace/conflict-checker by default.
2014-01-29 04:07:27 +01:00
"""
2014-01-28 15:25:40 +01:00
import sys
import subprocess
2014-01-28 22:44:39 +01:00
import os
import os.path
from collections import OrderedDict
2014-01-28 15:25:40 +01:00
2014-01-29 04:07:27 +01:00
from pkg_resources import load_entry_point, DistributionNotFound
status = OrderedDict()
2014-01-28 16:14:10 +01:00
testmodule = 'qutebrowser'
2014-01-28 15:25:40 +01:00
def run(name, args=None):
2014-01-29 04:07:27 +01:00
""" Run a checker with optional args.
name -- Name of the checker/binary
args -- Option list of arguments to pass
"""
2014-01-28 16:14:10 +01:00
sys.argv = [name, testmodule]
2014-01-28 15:25:40 +01:00
if args is not None:
sys.argv += args
print("====== {} ======".format(name))
try:
load_entry_point(name, 'console_scripts', name)()
except SystemExit as e:
status[name] = e
except DistributionNotFound:
if args is None:
args = []
try:
status[name] = subprocess.call([name] + args)
except FileNotFoundError as e:
print('{}: {}'.format(e.__class__.__name__, e))
status[name] = None
2014-01-28 15:25:40 +01:00
except Exception as e:
2014-01-28 15:50:11 +01:00
print('{}: {}'.format(e.__class__.__name__, e))
2014-01-28 15:25:40 +01:00
status[name] = None
print()
2014-02-04 22:10:27 +01:00
def check_line():
"""Checks a filetree for CRLFs, conflict markers and weird whitespace"""
print("====== line ======")
2014-01-28 22:44:39 +01:00
ret = []
try:
for (dirpath, dirnames, filenames) in os.walk(testmodule):
for name in [e for e in filenames if e.endswith('.py')]:
fn = os.path.join(dirpath, name)
2014-02-04 22:10:27 +01:00
ret.append(_check_line(fn))
status['line'] = all(ret)
2014-01-28 22:44:39 +01:00
except Exception as e:
print('{}: {}'.format(e.__class__.__name__, e))
2014-02-04 22:10:27 +01:00
status['line'] = None
2014-01-28 22:44:39 +01:00
print()
2014-02-04 22:10:27 +01:00
def _check_line(fn):
2014-01-28 22:44:39 +01:00
with open(fn, 'rb') as f:
for line in f:
if b'\r\n' in line:
print('Found CRLF in {}'.format(fn))
return False
2014-02-04 22:10:27 +01:00
elif any([line.decode('UTF-8').startswith(c * 7) for c in "<>=|"]):
print('Found conflict marker in {}'.format(fn))
return False
elif any([line.decode('UTF-8').rstrip('\r\n').endswith(c)
for c in " \t"]):
print('Found whitespace at line ending in {}'.format(fn))
return False
elif b' \t' in line or b'\t ' in line:
print('Found tab-space mix in {}'.format(fn))
return False
2014-01-28 22:44:39 +01:00
return True
2014-01-28 16:13:11 +01:00
pylint_disable = [
2014-01-29 08:36:44 +01:00
'import-error', # import seems unreliable
2014-01-28 19:51:49 +01:00
'no-name-in-module',
2014-01-29 08:36:44 +01:00
'invalid-name', # short variable names can be nice
'star-args', # we want to use this
2014-01-30 15:55:08 +01:00
'fixme',
2014-01-29 08:36:44 +01:00
'too-many-public-methods', # Basically unavoidable with Qt
2014-01-30 15:55:08 +01:00
'no-self-use',
2014-01-29 08:36:44 +01:00
'super-on-old-class', # These don't even exist in python3
2014-01-28 19:51:49 +01:00
'old-style-class',
2014-01-30 15:55:08 +01:00
'global-statement',
2014-01-29 08:36:44 +01:00
'abstract-class-little-used', # False-positives
2014-01-30 15:55:08 +01:00
'bad-builtin', # map/filter can be nicer than comprehensions
'too-many-arguments',
'too-many-locals',
2014-01-28 16:13:11 +01:00
]
2014-01-28 23:13:06 +01:00
flake8_disable = [
'E241', # Multiple spaces after ,
]
2014-01-28 15:56:50 +01:00
run('pylint', ['--ignore=appdirs.py', '--output-format=colorized',
2014-01-28 16:13:11 +01:00
'--reports=no', '--disable=' + ','.join(pylint_disable)])
2014-01-30 20:49:08 +01:00
# FIXME what the hell is the flake8 exit status?
2014-01-28 23:13:06 +01:00
run('flake8', ['--max-complexity=10', '--exclude=appdirs.py',
'--ignore=' + ''.join(flake8_disable)])
2014-02-04 22:10:27 +01:00
check_line()
2014-01-28 15:25:40 +01:00
print('Exit status values:')
for (k, v) in status.items():
print(' {} - {}'.format(k, v))
2014-01-30 20:49:08 +01:00
if all([val in [True, 0] for val in status]):
sys.exit(0)
else:
sys.exit(1)