mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-11 15:24:18 +00:00
Further simplification thanks to pep8
This commit is contained in:
parent
25dd8c445e
commit
b97d869e20
2 changed files with 14 additions and 45 deletions
|
|
@ -5,11 +5,22 @@ import pyflakes.api
|
||||||
import pyflakes.checker
|
import pyflakes.checker
|
||||||
import select
|
import select
|
||||||
from flake8 import mccabe
|
from flake8 import mccabe
|
||||||
from flake8.util import (_initpep8, skip_file, get_parser, read_config,
|
from flake8.util import _initpep8, skip_file, get_parser, Flake8Reporter
|
||||||
Flake8Reporter)
|
|
||||||
|
|
||||||
pep8style = None
|
pep8style = None
|
||||||
|
|
||||||
|
if sys.platform.startswith('win'):
|
||||||
|
pep8.DEFAULT_CONFIG = os.path.expanduser(r'~\.flake8')
|
||||||
|
else:
|
||||||
|
pep8.DEFAULT_CONFIG = os.path.join(
|
||||||
|
os.getenv('XDG_CONFIG_HOME') or os.path.expanduser('~/.config'),
|
||||||
|
'flake8'
|
||||||
|
)
|
||||||
|
|
||||||
|
PROJECT_CONFIG = ['.flake8']
|
||||||
|
PROJECT_CONFIG.extend(pep8.PROJECT_CONFIG)
|
||||||
|
pep8.PROJECT_CONFIG = tuple(PROJECT_CONFIG)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global pep8style
|
global pep8style
|
||||||
|
|
@ -25,8 +36,6 @@ def main():
|
||||||
from flake8.hooks import install_hook
|
from flake8.hooks import install_hook
|
||||||
install_hook()
|
install_hook()
|
||||||
|
|
||||||
read_config(opts, parser)
|
|
||||||
|
|
||||||
warnings = 0
|
warnings = 0
|
||||||
stdin = None
|
stdin = None
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,50 +45,10 @@ def get_parser():
|
||||||
parser.add_option('-V', '--version', action='callback',
|
parser.add_option('-V', '--version', action='callback',
|
||||||
callback=version,
|
callback=version,
|
||||||
help='Print the version info for flake8')
|
help='Print the version info for flake8')
|
||||||
|
parser.prog = os.path.basename(sys.argv[0])
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
def read_config(opts, opt_parser):
|
|
||||||
configs = ('.flake8', '.pep8', 'tox.ini', 'setup.cfg',
|
|
||||||
os.path.expanduser(r'~\.flake8'),
|
|
||||||
os.path.join(os.path.expanduser('~/.config'), 'flake8'))
|
|
||||||
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 skip_warning(warning, ignore=[]):
|
def skip_warning(warning, ignore=[]):
|
||||||
# XXX quick dirty hack, just need to keep the line in the warning
|
# XXX quick dirty hack, just need to keep the line in the warning
|
||||||
if not hasattr(warning, 'message') or ignore is None:
|
if not hasattr(warning, 'message') or ignore is None:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue