mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-30 18:56:53 +00:00
Fixes #56.
This is a really horrible hack, but hopefully future versions of pep8 will bring a nicer API to manipulate. I'll be gladly contributing to it.
This commit is contained in:
parent
a88ec88c62
commit
1d247709a0
2 changed files with 62 additions and 3 deletions
|
|
@ -4,10 +4,10 @@ import pep8
|
|||
import flakey
|
||||
import select
|
||||
from flake8 import mccabe
|
||||
from flake8.util import _initpep8, skip_file, get_parser
|
||||
from flake8.util import (_initpep8, skip_file, get_parser, read_config,
|
||||
merge_opts)
|
||||
|
||||
pep8style = None
|
||||
pep8.PROJECT_CONFIG = ('.flake8', '.pep8', 'tox.ini', 'setup.cfg')
|
||||
|
||||
|
||||
def main():
|
||||
|
|
@ -39,8 +39,11 @@ def main():
|
|||
sys.argv.pop(0)
|
||||
sys.argv.insert(0, 'pep8')
|
||||
|
||||
read_config(opts, parser)
|
||||
|
||||
# We then have to re-parse argv to make sure pep8 is properly initialized
|
||||
pep8style = pep8.StyleGuide(parse_argv=True, config_file=True)
|
||||
merge_opts(pep8style.options, opts)
|
||||
warnings = 0
|
||||
stdin = None
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import os
|
|||
import sys
|
||||
from io import StringIO
|
||||
import optparse
|
||||
import pep8
|
||||
|
||||
try:
|
||||
# Python 2
|
||||
|
|
@ -19,7 +20,6 @@ def get_parser():
|
|||
"""Create a custom OptionParser"""
|
||||
from flake8 import __version__
|
||||
import flakey
|
||||
import pep8
|
||||
parser = pep8.get_parser()
|
||||
|
||||
def version(option, opt, value, parser):
|
||||
|
|
@ -47,6 +47,62 @@ def get_parser():
|
|||
return parser
|
||||
|
||||
|
||||
def read_config(opts, opt_parser):
|
||||
configs = ('.flake8', '.pep8', 'tox.ini', 'setup.cfg')
|
||||
parser = ConfigParser()
|
||||
files_found = parser.read(configs)
|
||||
if not (files_found and parser.has_section('flake8')):
|
||||
return
|
||||
|
||||
if opts.verbose:
|
||||
print("Found local configuration file(s): {0}".format(
|
||||
', '.join(files_found)))
|
||||
|
||||
option_list = dict([(o.dest, o.type or o.action)
|
||||
for o in opt_parser.option_list])
|
||||
|
||||
for o in parser.options('flake8'):
|
||||
v = parser.get('flake8', o)
|
||||
|
||||
if opts.verbose > 1:
|
||||
print(" {0} = {1}".format(o, v))
|
||||
|
||||
normed = o.replace('-', '_')
|
||||
if normed not in option_list:
|
||||
print("Unknown option: {0}".format(o))
|
||||
|
||||
opt_type = option_list[normed]
|
||||
|
||||
if opt_type in ('int', 'count'):
|
||||
v = int(v)
|
||||
elif opt_type in ('store_true', 'store_false'):
|
||||
v = True if v == 'True' else False
|
||||
|
||||
setattr(opts, normed, v)
|
||||
|
||||
for attr in ('filename', 'exclude', 'ignore', 'select'):
|
||||
val = getattr(opts, attr)
|
||||
if hasattr(val, 'split'):
|
||||
setattr(opts, attr, val.split(','))
|
||||
|
||||
|
||||
def merge_opts(pep8_opts, our_opts):
|
||||
pep8_parser = pep8.get_parser()
|
||||
|
||||
for o in pep8_parser.option_list:
|
||||
if not (o.dest and getattr(our_opts, o.dest)):
|
||||
continue
|
||||
|
||||
new_val = getattr(our_opts, o.dest)
|
||||
old_val = getattr(pep8_opts, o.dest)
|
||||
if isinstance(old_val, list):
|
||||
old_val.extend(new_val)
|
||||
continue
|
||||
elif isinstance(old_val, tuple):
|
||||
new_val = tuple(new_val)
|
||||
setattr(pep8_opts, o.dest, new_val)
|
||||
|
||||
|
||||
def skip_warning(warning, ignore=[]):
|
||||
# XXX quick dirty hack, just need to keep the line in the warning
|
||||
if not hasattr(warning, 'message') or ignore is None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue