run_checks: Refactor running of checkers
This commit is contained in:
parent
9281f30c7b
commit
dbc9a53e1c
@ -40,6 +40,7 @@ import tokenize
|
|||||||
import configparser
|
import configparser
|
||||||
import argparse
|
import argparse
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
import pep257
|
import pep257
|
||||||
from pkg_resources import load_entry_point, DistributionNotFound
|
from pkg_resources import load_entry_point, DistributionNotFound
|
||||||
@ -55,15 +56,15 @@ config = configparser.ConfigParser()
|
|||||||
config.read('.run_checks')
|
config.read('.run_checks')
|
||||||
|
|
||||||
|
|
||||||
def run(name, target=None, args=None):
|
def run(name, target=None):
|
||||||
"""Run a checker via distutils with optional args.
|
"""Run a checker via distutils with optional args.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
name: Name of the checker/binary
|
name: Name of the checker/binary
|
||||||
target: The package to check
|
target: The package to check
|
||||||
args: Option list of arguments to pass
|
|
||||||
"""
|
"""
|
||||||
# pylint: disable=too-many-branches
|
# pylint: disable=too-many-branches
|
||||||
|
args = _get_args(name)
|
||||||
if name == 'pylint':
|
if name == 'pylint':
|
||||||
scriptdir = os.path.abspath(os.path.dirname(__file__))
|
scriptdir = os.path.abspath(os.path.dirname(__file__))
|
||||||
if 'PYTHONPATH' in os.environ:
|
if 'PYTHONPATH' in os.environ:
|
||||||
@ -80,11 +81,11 @@ def run(name, target=None, args=None):
|
|||||||
args.append(target)
|
args.append(target)
|
||||||
if args is not None:
|
if args is not None:
|
||||||
sys.argv += args
|
sys.argv += args
|
||||||
print("------ {} ------".format(name))
|
|
||||||
try:
|
try:
|
||||||
ep = load_entry_point(name, 'console_scripts', name)
|
ep = load_entry_point(name, 'console_scripts', name)
|
||||||
ep()
|
ep()
|
||||||
except SystemExit as e:
|
except SystemExit as e:
|
||||||
|
import pdb; pdb.set_trace() # XXX BREAKPOINT
|
||||||
status[status_key] = e
|
status[status_key] = e
|
||||||
except DistributionNotFound:
|
except DistributionNotFound:
|
||||||
if args is None:
|
if args is None:
|
||||||
@ -105,12 +106,12 @@ def run(name, target=None, args=None):
|
|||||||
print()
|
print()
|
||||||
|
|
||||||
|
|
||||||
def check_pep257(target, args=None):
|
def check_pep257(target):
|
||||||
"""Run pep257 checker with args passed."""
|
"""Run pep257 checker with args passed."""
|
||||||
|
args = _get_args('pep257')
|
||||||
sys.argv = ['pep257', target]
|
sys.argv = ['pep257', target]
|
||||||
if args is not None:
|
if args is not None:
|
||||||
sys.argv += args
|
sys.argv += args
|
||||||
print("------ pep257 ------")
|
|
||||||
try:
|
try:
|
||||||
status['pep257_' + target] = pep257.main(*pep257.parse_options())
|
status['pep257_' + target] = pep257.main(*pep257.parse_options())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -121,7 +122,6 @@ def check_pep257(target, args=None):
|
|||||||
|
|
||||||
def check_unittest():
|
def check_unittest():
|
||||||
"""Run the unittest checker."""
|
"""Run the unittest checker."""
|
||||||
print("==================== unittest ====================")
|
|
||||||
suite = unittest.TestLoader().discover('.')
|
suite = unittest.TestLoader().discover('.')
|
||||||
result = unittest.TextTestRunner().run(suite)
|
result = unittest.TextTestRunner().run(suite)
|
||||||
print()
|
print()
|
||||||
@ -130,7 +130,6 @@ def check_unittest():
|
|||||||
|
|
||||||
def check_git():
|
def check_git():
|
||||||
"""Check for uncommited git files.."""
|
"""Check for uncommited git files.."""
|
||||||
print("==================== git ====================")
|
|
||||||
if not os.path.isdir(".git"):
|
if not os.path.isdir(".git"):
|
||||||
print("No .git dir, ignoring")
|
print("No .git dir, ignoring")
|
||||||
status['git'] = False
|
status['git'] = False
|
||||||
@ -154,7 +153,6 @@ def check_git():
|
|||||||
|
|
||||||
def check_vcs_conflict(target):
|
def check_vcs_conflict(target):
|
||||||
"""Check VCS conflict markers."""
|
"""Check VCS conflict markers."""
|
||||||
print("------ VCS conflict markers ------")
|
|
||||||
try:
|
try:
|
||||||
ok = True
|
ok = True
|
||||||
for (dirpath, _dirnames, filenames) in os.walk(target):
|
for (dirpath, _dirnames, filenames) in os.walk(target):
|
||||||
@ -226,27 +224,55 @@ def _get_args(checker):
|
|||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
|
def _get_checkers(args):
|
||||||
|
"""Get a dict of checkers we need to execute."""
|
||||||
|
checkers = OrderedDict([
|
||||||
|
('global', OrderedDict([
|
||||||
|
('unittest', check_unittest),
|
||||||
|
('git', check_git),
|
||||||
|
])),
|
||||||
|
('setup', OrderedDict([
|
||||||
|
('pyroma', partial(run, 'pyroma')),
|
||||||
|
('check-manifest', partial(run, 'check-manifest')),
|
||||||
|
])),
|
||||||
|
])
|
||||||
|
for target in config.get('DEFAULT', 'targets').split(','):
|
||||||
|
checkers[target] = OrderedDict([
|
||||||
|
('pep257', partial(check_pep257, target)),
|
||||||
|
('flake8', partial(run, 'flake8', target)),
|
||||||
|
('vcs', partial(check_vcs_conflict, target)),
|
||||||
|
('pylint', partial(run, 'pylint', target)),
|
||||||
|
])
|
||||||
|
return checkers
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main entry point."""
|
"""Main entry point."""
|
||||||
parser = argparse.ArgumentParser(description='Run various checkers.')
|
parser = argparse.ArgumentParser(description='Run various checkers.')
|
||||||
parser.add_argument('-s', '--setup', help="Run additional setup checks",
|
parser.add_argument('-s', '--setup', help="Run additional setup checks",
|
||||||
action='store_true')
|
action='store_true')
|
||||||
|
parser.add_argument('checkers', help="Checkers to run (or 'all')",
|
||||||
|
default='all', nargs='?')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
check_unittest()
|
checkers = _get_checkers(args)
|
||||||
check_git()
|
|
||||||
for trg in config.get('DEFAULT', 'targets').split(','):
|
|
||||||
print("==================== {} ====================".format(trg))
|
|
||||||
check_pep257(trg, _get_args('pep257'))
|
|
||||||
for chk in ('pylint', 'flake8'):
|
|
||||||
# FIXME what the hell is the flake8 exit status?
|
|
||||||
run(chk, trg, _get_args(chk))
|
|
||||||
check_vcs_conflict(trg)
|
|
||||||
|
|
||||||
|
groups = ['global']
|
||||||
|
groups += config.get('DEFAULT', 'targets').split(',')
|
||||||
if args.setup:
|
if args.setup:
|
||||||
print("==================== Setup checks ====================")
|
groups.append('setup')
|
||||||
for chk in ('pyroma', 'check-manifest'):
|
|
||||||
run(chk, args=_get_args(chk))
|
for group in groups:
|
||||||
|
print()
|
||||||
|
print("==================== {} ====================".format(group))
|
||||||
|
if args.checkers == 'all':
|
||||||
|
configured_checkers = None
|
||||||
|
else:
|
||||||
|
configured_checkers = args.checkers.split(',')
|
||||||
|
for name, func in checkers[group].items():
|
||||||
|
if configured_checkers is None or name in configured_checkers:
|
||||||
|
print("------ {} ------".format(name))
|
||||||
|
func()
|
||||||
|
|
||||||
print("Exit status values:")
|
print("Exit status values:")
|
||||||
for (k, v) in status.items():
|
for (k, v) in status.items():
|
||||||
|
Loading…
Reference in New Issue
Block a user