run_checks: Add a --print-version argument.

This commit is contained in:
Florian Bruhin 2015-01-19 00:45:01 +01:00
parent 380537d49c
commit 1e8729eac7

View File

@ -78,18 +78,21 @@ def _adjusted_pythonpath(name):
del os.environ['PYTHONPATH'] del os.environ['PYTHONPATH']
def run(name, target=None): def run(name, target=None, print_version=False):
"""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
print_version: Whether to print the checker version.
""" """
# pylint: disable=too-many-branches # pylint: disable=too-many-branches
args = _get_args(name) args = _get_args(name)
if target is not None: if target is not None:
args.append(target) args.append(target)
with _adjusted_pythonpath(name): with _adjusted_pythonpath(name):
if print_version:
subprocess.call([name, '--version'])
try: try:
status = subprocess.call([name] + args) status = subprocess.call([name] + args)
except OSError: except OSError:
@ -211,7 +214,7 @@ def _get_args(checker):
return args return args
def _get_checkers(): def _get_checkers(args):
"""Get a dict of checkers we need to execute.""" """Get a dict of checkers we need to execute."""
# "Static" checkers # "Static" checkers
checkers = collections.OrderedDict([ checkers = collections.OrderedDict([
@ -220,17 +223,18 @@ def _get_checkers():
('git', check_git), ('git', check_git),
])), ])),
('setup', collections.OrderedDict([ ('setup', collections.OrderedDict([
('pyroma', functools.partial(run, 'pyroma')), ('pyroma', functools.partial(run, 'pyroma', args.version)),
('check-manifest', functools.partial(run, 'check-manifest')), ('check-manifest', functools.partial(run, 'check-manifest',
args.version)),
])), ])),
]) ])
# "Dynamic" checkers which exist once for each target. # "Dynamic" checkers which exist once for each target.
for target in config.get('DEFAULT', 'targets').split(','): for target in config.get('DEFAULT', 'targets').split(','):
checkers[target] = collections.OrderedDict([ checkers[target] = collections.OrderedDict([
('pep257', functools.partial(run, 'pep257', target)), ('pep257', functools.partial(run, 'pep257', target, args.version)),
('flake8', functools.partial(run, 'flake8', target)), ('flake8', functools.partial(run, 'flake8', target, args.version)),
('vcs', functools.partial(check_vcs_conflict, target)), ('vcs', functools.partial(check_vcs_conflict, target)),
('pylint', functools.partial(run, 'pylint', target)), ('pylint', functools.partial(run, 'pylint', target, args.version)),
]) ])
return checkers return checkers
@ -254,6 +258,8 @@ def _parse_args():
parser.add_argument('-q', '--quiet', parser.add_argument('-q', '--quiet',
help="Don't print unnecessary headers.", help="Don't print unnecessary headers.",
action='store_true') action='store_true')
parser.add_argument('-V', '--version',
help="Print checker versions.", action='store_true')
parser.add_argument('checkers', help="Checkers to run (or 'all')", parser.add_argument('checkers', help="Checkers to run (or 'all')",
default='all', nargs='?') default='all', nargs='?')
return parser.parse_args() return parser.parse_args()
@ -269,7 +275,7 @@ def main():
exit_status_bool = {} exit_status_bool = {}
args = _parse_args() args = _parse_args()
checkers = _get_checkers() checkers = _get_checkers(args)
groups = ['global'] groups = ['global']
groups += config.get('DEFAULT', 'targets').split(',') groups += config.get('DEFAULT', 'targets').split(',')