Style fixes in run_checks

This commit is contained in:
Florian Bruhin 2014-02-10 11:07:21 +01:00
parent e49a0aa0ed
commit 921464ef5e

View File

@ -26,7 +26,12 @@ import os
import os.path import os.path
from collections import OrderedDict from collections import OrderedDict
try:
import pep257 import pep257
except ImportError:
do_check_257 = False
else:
do_check_257 = True
from pkg_resources import load_entry_point, DistributionNotFound from pkg_resources import load_entry_point, DistributionNotFound
status = OrderedDict() status = OrderedDict()
@ -74,6 +79,7 @@ options = {
}, },
} }
def run(name, args=None): def run(name, args=None):
""" Run a checker via distutils with optional args. """ Run a checker via distutils with optional args.
@ -101,6 +107,7 @@ def run(name, args=None):
status[name] = None status[name] = None
print() print()
def check_pep257(args=None): def check_pep257(args=None):
sys.argv = ['pep257', options['target']] sys.argv = ['pep257', options['target']]
if args is not None: if args is not None:
@ -110,9 +117,10 @@ def check_pep257(args=None):
status['pep257'] = pep257.main(*pep257.parse_options()) status['pep257'] = pep257.main(*pep257.parse_options())
except Exception as e: except Exception as e:
print('{}: {}'.format(e.__class__.__name__, e)) print('{}: {}'.format(e.__class__.__name__, e))
status[name] = None status['pep257'] = None
print() print()
def check_line(): def check_line():
"""Checks a filetree for CRLFs, conflict markers and weird whitespace""" """Checks a filetree for CRLFs, conflict markers and weird whitespace"""
print("====== line ======") print("====== line ======")
@ -128,6 +136,7 @@ def check_line():
status['line'] = None status['line'] = None
print() print()
def _check_line(fn): def _check_line(fn):
with open(fn, 'rb') as f: with open(fn, 'rb') as f:
for line in f: for line in f:
@ -146,6 +155,7 @@ def _check_line(fn):
return False return False
return True return True
def _get_args(checker): def _get_args(checker):
args = [] args = []
if checker == 'pylint': if checker == 'pylint':
@ -166,12 +176,14 @@ def _get_args(checker):
args = [] args = []
try: try:
args += ['--ignore=' + ','.join(options['disable']['pep257'])] args += ['--ignore=' + ','.join(options['disable']['pep257'])]
args += ['--match=(?!{}).*\.py'.format('|'.join(options['exclude']))] args += ['--match=(?!{}).*\.py'.format('|'.join(
options['exclude']))]
args += options['other']['pep257'] args += options['other']['pep257']
except KeyError: except KeyError:
pass pass
return args return args
if do_check_257:
check_pep257(_get_args('pep257')) check_pep257(_get_args('pep257'))
for checker in ['pylint', 'flake8']: for checker in ['pylint', 'flake8']:
# FIXME what the hell is the flake8 exit status? # FIXME what the hell is the flake8 exit status?