From b97d869e201e9da48f0cd2e9843297d34109cbae Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Sun, 10 Feb 2013 15:10:03 -0500 Subject: [PATCH] Further simplification thanks to pep8 --- flake8/main.py | 17 +++++++++++++---- flake8/util.py | 42 +----------------------------------------- 2 files changed, 14 insertions(+), 45 deletions(-) diff --git a/flake8/main.py b/flake8/main.py index 8222e9c..3a763a9 100644 --- a/flake8/main.py +++ b/flake8/main.py @@ -5,11 +5,22 @@ import pyflakes.api import pyflakes.checker import select from flake8 import mccabe -from flake8.util import (_initpep8, skip_file, get_parser, read_config, - Flake8Reporter) +from flake8.util import _initpep8, skip_file, get_parser, Flake8Reporter 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(): global pep8style @@ -25,8 +36,6 @@ def main(): from flake8.hooks import install_hook install_hook() - read_config(opts, parser) - warnings = 0 stdin = None diff --git a/flake8/util.py b/flake8/util.py index 0afdd3c..6083e5c 100644 --- a/flake8/util.py +++ b/flake8/util.py @@ -45,50 +45,10 @@ def get_parser(): parser.add_option('-V', '--version', action='callback', callback=version, help='Print the version info for flake8') + parser.prog = os.path.basename(sys.argv[0]) 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=[]): # XXX quick dirty hack, just need to keep the line in the warning if not hasattr(warning, 'message') or ignore is None: