Code re-org for my sanity.
This commit is contained in:
parent
3461709ebf
commit
f70aea7ec3
|
@ -24,39 +24,6 @@ _ = gettext.gettext
|
||||||
# |___/
|
# |___/
|
||||||
|
|
||||||
|
|
||||||
def find_config_file(options, base):
|
|
||||||
""" Returns the configuration file from a prioritized list of locations.
|
|
||||||
|
|
||||||
Locations are prioritized as:
|
|
||||||
1. From the command line. Fail if specified but not found
|
|
||||||
2. The repository's root directory, as the file .git-lint
|
|
||||||
3. The repository's root directory, as the file .git-lint/config
|
|
||||||
4. The user's home directory, as file .git-lint
|
|
||||||
5. The user's home directory, as the file .git-lint/config
|
|
||||||
|
|
||||||
If no configuration file is found, this is an error.
|
|
||||||
"""
|
|
||||||
|
|
||||||
if 'config' in options:
|
|
||||||
config = options['config']
|
|
||||||
configpath = os.path.abspath(config)
|
|
||||||
if not os.path.isfile(configpath):
|
|
||||||
sys.exit(_('Configuration file not found: {}\n').format(config))
|
|
||||||
return configpath
|
|
||||||
|
|
||||||
home = os.environ.get('HOME', None)
|
|
||||||
possibles = [os.path.join(base, '.git-lint'),
|
|
||||||
os.path.join(base, '.git-lint/config')] + ((home and [
|
|
||||||
os.path.join(home, '.git-lint'),
|
|
||||||
os.path.join(home, '.git-lint/config')]) or [])
|
|
||||||
|
|
||||||
matches = [p for p in possibles if os.path.isfile(p)]
|
|
||||||
if len(matches) == 0:
|
|
||||||
sys.exit(_('No configuration file found, tried: {}').format(':'.join(possibles)))
|
|
||||||
|
|
||||||
return matches[0]
|
|
||||||
|
|
||||||
|
|
||||||
# (commandLineDictionary, repositoryLocation) -> (configurationDictionary | exit)
|
# (commandLineDictionary, repositoryLocation) -> (configurationDictionary | exit)
|
||||||
def load_config(options, base):
|
def load_config(options, base):
|
||||||
"""Loads the git-lint configuration file.
|
"""Loads the git-lint configuration file.
|
||||||
|
@ -70,6 +37,38 @@ def load_config(options, base):
|
||||||
files for specific linters.
|
files for specific linters.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def find_config_file(options, base):
|
||||||
|
""" Returns the configuration file from a prioritized list of locations.
|
||||||
|
|
||||||
|
Locations are prioritized as:
|
||||||
|
1. From the command line. Fail if specified but not found
|
||||||
|
2. The repository's root directory, as the file .git-lint
|
||||||
|
3. The repository's root directory, as the file .git-lint/config
|
||||||
|
4. The user's home directory, as file .git-lint
|
||||||
|
5. The user's home directory, as the file .git-lint/config
|
||||||
|
|
||||||
|
If no configuration file is found, this is an error.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if 'config' in options:
|
||||||
|
config = options['config']
|
||||||
|
configpath = os.path.abspath(config)
|
||||||
|
if not os.path.isfile(configpath):
|
||||||
|
sys.exit(_('Configuration file not found: {}\n').format(config))
|
||||||
|
return configpath
|
||||||
|
|
||||||
|
home = os.environ.get('HOME', None)
|
||||||
|
possibles = [os.path.join(base, '.git-lint'),
|
||||||
|
os.path.join(base, '.git-lint/config')] + ((home and [
|
||||||
|
os.path.join(home, '.git-lint'),
|
||||||
|
os.path.join(home, '.git-lint/config')]) or [])
|
||||||
|
|
||||||
|
matches = [p for p in possibles if os.path.isfile(p)]
|
||||||
|
if len(matches) == 0:
|
||||||
|
sys.exit(_('No configuration file found, tried: {}').format(':'.join(possibles)))
|
||||||
|
|
||||||
|
return matches[0]
|
||||||
|
|
||||||
Linter = namedtuple('Linter', ['name', 'linter'])
|
Linter = namedtuple('Linter', ['name', 'linter'])
|
||||||
path = find_config_file(options, base)
|
path = find_config_file(options, base)
|
||||||
configloader = configparser.SafeConfigParser()
|
configloader = configparser.SafeConfigParser()
|
||||||
|
@ -193,12 +192,12 @@ def executable_exists(script, label):
|
||||||
return (len(possibles) and possibles.pop(0)) or False
|
return (len(possibles) and possibles.pop(0)) or False
|
||||||
|
|
||||||
|
|
||||||
def get_working_linter_names(config):
|
|
||||||
return [i.name for i in config
|
|
||||||
if executable_exists(i.linter['command'], i.name)]
|
|
||||||
|
|
||||||
|
|
||||||
def get_linter_status(config):
|
def get_linter_status(config):
|
||||||
|
|
||||||
|
def get_working_linter_names(config):
|
||||||
|
return [i.name for i in config
|
||||||
|
if executable_exists(i.linter['command'], i.name)]
|
||||||
|
|
||||||
working_linter_names = get_working_linter_names(config)
|
working_linter_names = get_working_linter_names(config)
|
||||||
broken_linter_names = (set([i.name for i in config]) - set(working_linter_names))
|
broken_linter_names = (set([i.name for i in config]) - set(working_linter_names))
|
||||||
return working_linter_names, broken_linter_names
|
return working_linter_names, broken_linter_names
|
||||||
|
|
|
@ -5,26 +5,25 @@ import gettext
|
||||||
_ = gettext.gettext
|
_ = gettext.gettext
|
||||||
|
|
||||||
|
|
||||||
def base_file_cleaner(files):
|
|
||||||
return [file.replace(git_base + '/', '', 1) for file in files]
|
|
||||||
|
|
||||||
|
|
||||||
# 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,
|
def print_report(results, unlintable_filenames, cant_lint_filenames,
|
||||||
broken_linter_names, unfindable_filenames, options={'bylinter': True}):
|
broken_linter_names, unfindable_filenames, options={'bylinter': True}):
|
||||||
|
|
||||||
|
def base_file_cleaner(files):
|
||||||
|
return [file.replace(git_base + '/', '', 1) for file in files]
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
sort_position = 1
|
sort_position = 1
|
||||||
grouping = _('Linter: {}')
|
grouping = _('Linter: {}')
|
||||||
if 'byfile' in options:
|
if 'byfile' in options:
|
||||||
|
|
Loading…
Reference in New Issue