run_checks: Add configfile
This commit is contained in:
parent
298f672084
commit
720e56cdc1
18
.run_checks
Normal file
18
.run_checks
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# vim: ft=dosini
|
||||||
|
|
||||||
|
[DEFAULT]
|
||||||
|
targets=qutebrowser,scripts
|
||||||
|
|
||||||
|
[pep257]
|
||||||
|
# D102: Docstring missing, will be handled by others
|
||||||
|
# D209: Blank line before closing """ (removed from PEP257)
|
||||||
|
# D402: First line should not be function's signature (false-positives)
|
||||||
|
disable=D102,D209,D402
|
||||||
|
exclude=test_.*,ez_setup
|
||||||
|
|
||||||
|
[pylint]
|
||||||
|
args=--output-format=colorized,--reports=no,--rcfile=.pylintrc
|
||||||
|
plugins=config,crlf,modeline,settrace
|
||||||
|
|
||||||
|
[flake8]
|
||||||
|
args=--config=.flake8
|
@ -37,6 +37,7 @@ import os.path
|
|||||||
import unittest
|
import unittest
|
||||||
import logging
|
import logging
|
||||||
import tokenize
|
import tokenize
|
||||||
|
import configparser
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -53,33 +54,9 @@ logging.basicConfig(level=logging.INFO, format='%(msg)s')
|
|||||||
|
|
||||||
status = OrderedDict()
|
status = OrderedDict()
|
||||||
|
|
||||||
options = {
|
|
||||||
'targets': ['qutebrowser', 'scripts'],
|
|
||||||
'disable': {
|
|
||||||
'pep257': [
|
|
||||||
'D102', # Docstring missing, will be handled by others
|
|
||||||
'D209', # Blank line before closing """ (removed from PEP257)
|
|
||||||
'D402', # First line should not be function's signature
|
|
||||||
# (false-positives)
|
|
||||||
],
|
|
||||||
},
|
|
||||||
'exclude': [],
|
|
||||||
'exclude_pep257': ['test_*', 'ez_setup'],
|
|
||||||
'other': {
|
|
||||||
'pylint': ['--output-format=colorized', '--reports=no',
|
|
||||||
'--rcfile=.pylintrc',
|
|
||||||
'--load-plugins=pylint_checkers.config,'
|
|
||||||
'pylint_checkers.crlf,'
|
|
||||||
'pylint_checkers.modeline,'
|
|
||||||
'pylint_checkers.settrace'],
|
|
||||||
'flake8': ['--config=.flake8'],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
if os.name == 'nt':
|
CONFIG = configparser.ConfigParser()
|
||||||
# pep257 uses cp1252 by default on Windows, which can't handle the unicode
|
CONFIG.read('.run_checks')
|
||||||
# chars in some files.
|
|
||||||
options['exclude_pep257'] += ['configdata.py', 'misc.py']
|
|
||||||
|
|
||||||
|
|
||||||
def run(name, target=None, args=None):
|
def run(name, target=None, args=None):
|
||||||
@ -205,51 +182,43 @@ def _get_args(checker):
|
|||||||
Return:
|
Return:
|
||||||
A list of commandline arguments.
|
A list of commandline arguments.
|
||||||
"""
|
"""
|
||||||
# pylint: disable=too-many-branches
|
|
||||||
|
def _get_optional_args(checker):
|
||||||
|
"""Get a list of arguments based on a comma-separated args config."""
|
||||||
|
try:
|
||||||
|
return CONFIG.get(checker, 'args').split(',')
|
||||||
|
except configparser.NoOptionError:
|
||||||
|
return []
|
||||||
|
|
||||||
|
def _get_flag(arg, checker, option):
|
||||||
|
"""Get a list of arguments based on a config option."""
|
||||||
|
try:
|
||||||
|
return ['--{}={}'.format(arg, CONFIG.get(checker, option))]
|
||||||
|
except configparser.NoOptionError:
|
||||||
|
return []
|
||||||
|
|
||||||
args = []
|
args = []
|
||||||
if checker == 'pylint':
|
if checker == 'pylint':
|
||||||
try:
|
args += _get_flag('disable', 'pylint', 'disable')
|
||||||
args += ['--disable=' + ','.join(options['disable']['pylint'])]
|
args += _get_flag('ignore', 'pylint', 'exclude')
|
||||||
except KeyError:
|
args += _get_optional_args('pylint')
|
||||||
pass
|
|
||||||
if options['exclude']:
|
|
||||||
try:
|
|
||||||
args += ['--ignore=' + ','.join(options['exclude'])]
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
args += options['other']['pylint']
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
elif checker == 'flake8':
|
elif checker == 'flake8':
|
||||||
try:
|
args += _get_flag('ignore', 'flake8', 'disable')
|
||||||
args += ['--ignore=' + ','.join(options['disable']['flake8'])]
|
args += _get_flag('exclude', 'flake8', 'exclude')
|
||||||
except KeyError:
|
args += _get_optional_args('flake8')
|
||||||
pass
|
|
||||||
if options['exclude']:
|
|
||||||
try:
|
|
||||||
args += ['--exclude=' + ','.join(options['exclude'])]
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
args += options['other']['flake8']
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
elif checker == 'pep257':
|
elif checker == 'pep257':
|
||||||
args = []
|
args += _get_flag('ignore', 'pep257', 'disable')
|
||||||
try:
|
try:
|
||||||
args += ['--ignore=' + ','.join(options['disable']['pep257'])]
|
excluded = CONFIG.get('pep257', 'exclude').split(',')
|
||||||
except KeyError:
|
except configparser.NoOptionError:
|
||||||
pass
|
excluded = []
|
||||||
try:
|
if os.name == 'nt':
|
||||||
args += [r'--match=(?!{}).*\.py'.format('|'.join(
|
# FIXME find a better solution
|
||||||
options['exclude'] + options['exclude_pep257']))]
|
# pep257 uses cp1252 by default on Windows, which can't handle the
|
||||||
except KeyError:
|
# unicode chars in some files.
|
||||||
pass
|
excluded += ['configdata', 'misc']
|
||||||
try:
|
args.append(r'--match=(?!{})\.py'.format('|'.join(excluded)))
|
||||||
args += options['other']['pep257']
|
args += _get_optional_args('pep257')
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
elif checker == 'pyroma':
|
elif checker == 'pyroma':
|
||||||
args = ['.']
|
args = ['.']
|
||||||
elif checker == 'check-manifest':
|
elif checker == 'check-manifest':
|
||||||
@ -260,7 +229,7 @@ def _get_args(checker):
|
|||||||
argv = sys.argv[:]
|
argv = sys.argv[:]
|
||||||
check_unittest()
|
check_unittest()
|
||||||
check_git()
|
check_git()
|
||||||
for trg in options['targets']:
|
for trg in CONFIG.get('DEFAULT', 'targets').split(','):
|
||||||
print("==================== {} ====================".format(trg))
|
print("==================== {} ====================".format(trg))
|
||||||
if do_check_257:
|
if do_check_257:
|
||||||
check_pep257(trg, _get_args('pep257'))
|
check_pep257(trg, _get_args('pep257'))
|
||||||
|
Loading…
Reference in New Issue
Block a user