Still cleaning up the working paths.
This commit is contained in:
parent
9029eef623
commit
3d7c0c1a3f
|
@ -1,18 +1,23 @@
|
|||
#!/usr/bin/env python
|
||||
from .options import OPTIONS
|
||||
from .option_handler import cleanup_options
|
||||
from .reporters import print_report, print_help
|
||||
from .reporters import print_report, print_help, print_linters
|
||||
from .git_lint import load_config, run_linters, git_base
|
||||
from getopt import GetoptError
|
||||
import sys
|
||||
|
||||
import gettext
|
||||
_ = gettext.gettext
|
||||
|
||||
def main(*args):
|
||||
NAME = 'git-lint'
|
||||
VERSION = '0.0.4'
|
||||
|
||||
|
||||
def main():
|
||||
if git_base is None:
|
||||
sys.exit(_('A git repository was not found.'))
|
||||
|
||||
(options, filenames, excluded_commands) = cleanup_options(OPTIONS, args)
|
||||
(options, filenames, excluded_commands) = cleanup_options(OPTIONS, sys.argv)
|
||||
|
||||
if len(excluded_commands) > 0:
|
||||
print(_('These command line options were ignored due to option precedence.'))
|
||||
|
@ -27,14 +32,14 @@ def main(*args):
|
|||
return 0
|
||||
|
||||
if 'version' in options:
|
||||
from .reporters get print_version
|
||||
from .reporters import print_version
|
||||
print_version(NAME, VERSION)
|
||||
return 0
|
||||
|
||||
if 'linters' in options:
|
||||
from .gitSlint import get_linter_status
|
||||
from .git_lint import get_linter_status
|
||||
working_linter_names, broken_linter_names = get_linter_status(config)
|
||||
print_linters(working_linter_names, broken_linter_names))
|
||||
print_linters(config, broken_linter_names)
|
||||
return 0
|
||||
|
||||
(results,
|
||||
|
@ -62,4 +67,4 @@ def main(*args):
|
|||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
sys.exit(main(*sys.argv))
|
||||
sys.exit(main())
|
||||
|
|
|
@ -17,10 +17,6 @@ except ImportError as e:
|
|||
_ = gettext.gettext
|
||||
|
||||
|
||||
VERSION = '0.0.4'
|
||||
NAME = 'git-lint'
|
||||
|
||||
|
||||
# ___ __ _ ___ _
|
||||
# / __|___ _ _ / _(_)__ _ | _ \___ __ _ __| |___ _ _
|
||||
# | (__/ _ \ ' \| _| / _` | | / -_) _` / _` / -_) '_|
|
||||
|
@ -170,20 +166,6 @@ class MatchFilter:
|
|||
return re.compile(r'\.' + '|'.join(cleaned) + r'$')
|
||||
|
||||
|
||||
# ICK. Mutation, references, and hidden assignment.
|
||||
def group_by(iterable, field_id):
|
||||
results = []
|
||||
keys = {}
|
||||
for obj in iterable:
|
||||
key = obj[field_id]
|
||||
if key in keys:
|
||||
keys[key].append(obj)
|
||||
continue
|
||||
keys[key] = [obj]
|
||||
results.append((key, keys[key]))
|
||||
return results
|
||||
|
||||
|
||||
# ___ _ _ _ _ _
|
||||
# / __| |_ ___ __| |__ | (_)_ _| |_ ___ _ _ ___
|
||||
# | (__| ' \/ -_) _| / / | | | ' \ _/ -_) '_(_-<
|
||||
|
@ -224,16 +206,6 @@ def get_linter_status(config):
|
|||
return working_linter_names, broken_linter_names
|
||||
|
||||
|
||||
def print_linters(config):
|
||||
print(_('Currently supported linters:'))
|
||||
working_linter_names, broken_linter_names = get_linter_status(config)
|
||||
for linter in config:
|
||||
print('{:<14} {}'.format(linter.name,
|
||||
((linter.name in broken_linter_names and
|
||||
_('(WARNING: executable not found)') or
|
||||
linter.linter.get('comment', '')))))
|
||||
|
||||
|
||||
# ___ _ _ _ _ __ __ _ _
|
||||
# / __|___| |_ | (_)__| |_ ___ / _| / _(_) |___ ___
|
||||
# | (_ / -_) _| | | (_-< _| / _ \ _| | _| | / -_|_-<
|
||||
|
@ -345,9 +317,9 @@ def get_filelist(options, extras):
|
|||
|
||||
class Runner:
|
||||
def __init__(self, options):
|
||||
self.runner = ('staging' in options and self.staging_wrapper) or self.workspace_wrapper
|
||||
self.runner = ('staging' in options and Runner.staging_wrapper) or Runner.workspace_wrapper
|
||||
|
||||
def __call__(run_linters, filenames):
|
||||
def __call__(self, run_linters, filenames):
|
||||
return self.runner(run_linters, filenames)
|
||||
|
||||
@staticmethod
|
||||
|
@ -378,8 +350,8 @@ class Runner:
|
|||
# |_|_\\_,_|_||_| |_|_|_||_\__| | .__/\__,_/__/__/
|
||||
# |_|
|
||||
|
||||
class Linter:
|
||||
def __init__(linters, filenames):
|
||||
class Linters:
|
||||
def __init__(self, linters, filenames):
|
||||
self.linters = linters
|
||||
self.filenames = filenames
|
||||
|
||||
|
@ -419,19 +391,19 @@ class Linter:
|
|||
result as a list of successes and failures. Failures have a
|
||||
return code and the output of the lint process.
|
||||
"""
|
||||
match_filter = make_match_filter([linter])
|
||||
match_filter = MatchFilter([linter])
|
||||
files = set([filename for filename in filenames if match_filter(filename)])
|
||||
return [self.run_external_linter(filename, linter.linter, linter.name) for filename in files]
|
||||
return [Linters.run_external_linter(filename, linter.linter, linter.name) for filename in files]
|
||||
|
||||
|
||||
def __call__(self, linters, filenames):
|
||||
def __call__(self):
|
||||
""" Returns a function to run a set of linters against a set of filenames
|
||||
|
||||
This returns a function because it's going to be wrapped in a
|
||||
runner to better handle stashing and restoring a staged commit.
|
||||
"""
|
||||
return reduce(operator.add,
|
||||
[run_one_linter(linter, self.filenames) for linter in self.linters], [])
|
||||
[Linters.run_one_linter(linter, self.filenames) for linter in self.linters], [])
|
||||
|
||||
|
||||
def dryrun(self):
|
||||
|
@ -480,10 +452,11 @@ def run_linters(options, config, extras):
|
|||
broken_linter_names, unfindable_filenames)
|
||||
|
||||
runner = Runner(options)
|
||||
linter = Linter(build_config_subset(working_linter_names),
|
||||
|
||||
linters = Linters(build_config_subset(working_linter_names),
|
||||
sorted(lintable_filenames))
|
||||
results = runner(linter, lintable_filenames)
|
||||
|
||||
results = runner(linters, lintable_filenames)
|
||||
|
||||
return (results, unlintable_filenames, cant_lint_filenames,
|
||||
broken_linter_names, unfindable_filenames)
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2015 Elf M. Sternberg
|
||||
# Author: Elf M. Sternberg
|
||||
#
|
||||
|
||||
import getopt
|
||||
|
||||
# This was a lot shorter and smarter in Hy...
|
||||
|
||||
|
@ -71,7 +70,7 @@ def cleanup_options(options, commandline):
|
|||
|
||||
optstringsshort = ''.join([shortoptstogo(opt) for opt in options])
|
||||
optstringslong = [longoptstogo(opt) for opt in options]
|
||||
(options, filenames) = getopt.getopt(commandline[1:],
|
||||
(chosen_options, filenames) = getopt.getopt(commandline[1:],
|
||||
optstringsshort,
|
||||
optstringslong)
|
||||
|
||||
|
@ -80,6 +79,6 @@ def cleanup_options(options, commandline):
|
|||
|
||||
# Remove any options that are superseded by others.
|
||||
(ret, excluded) = remove_conflicted_options(
|
||||
optlist, reduce(streamline_options, options, {}))
|
||||
options, reduce(streamline_options, chosen_options, {}))
|
||||
|
||||
return (ret, filenames, excluded)
|
||||
|
|
|
@ -1,6 +1,19 @@
|
|||
import gettext
|
||||
_ = gettext.gettext
|
||||
|
||||
# ICK. Mutation, references, and hidden assignment.
|
||||
def group_by(iterable, field_id):
|
||||
results = []
|
||||
keys = {}
|
||||
for obj in iterable:
|
||||
key = obj[field_id]
|
||||
if key in keys:
|
||||
keys[key].append(obj)
|
||||
continue
|
||||
keys[key] = [obj]
|
||||
results.append((key, keys[key]))
|
||||
return results
|
||||
|
||||
def print_report(results, unlintable_filenames, cant_lint_filenames,
|
||||
broken_linter_names, unfindable_filenames, options = {'bylinter': True}):
|
||||
sort_position = 1
|
||||
|
@ -31,14 +44,13 @@ def print_help(options, name):
|
|||
print(_('Usage: {} [options] [filenames]').format(name))
|
||||
for item in options:
|
||||
print(' -{:<1} --{:<12} {}'.format(item[0], item[1], item[3]))
|
||||
return sys.exit()
|
||||
|
||||
|
||||
def print_version(name, version):
|
||||
print(_'{} {} Copyright (c) 2009, 2016 Kennth M. "Elf" Sternberg').format(name, version))
|
||||
print(_('{} {} Copyright (c) 2009, 2016 Kennth M. "Elf" Sternberg')).format(name, version)
|
||||
|
||||
|
||||
def print_linters(working_linter_names, broken_linter_names):
|
||||
def print_linters(config, broken_linter_names):
|
||||
print(_('Currently supported linters:'))
|
||||
for linter in config:
|
||||
print('{:<14} {}'.format(linter.name,
|
||||
|
|
Loading…
Reference in New Issue