Skip to content

Commit ed1e25c

Browse files
committed
Update the ordering of configs parsed; issue #368 / #369
Remove the default of ~/.config/pep8, and instead parse that explictly. If a command line option is passed using --config, then it is the only config handled.
1 parent 57372c6 commit ed1e25c

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

pep8.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,14 @@
6868
DEFAULT_IGNORE = 'E121,E123,E126,E226,E24,E704'
6969
try:
7070
if sys.platform == 'win32':
71-
DEFAULT_CONFIG = os.path.expanduser(r'~\.pep8')
71+
USER_CONFIG = os.path.expanduser(r'~\.pep8')
7272
else:
73-
DEFAULT_CONFIG = os.path.join(os.getenv('XDG_CONFIG_HOME') or
74-
os.path.expanduser('~/.config'), 'pep8')
73+
USER_CONFIG = os.path.join(
74+
os.getenv('XDG_CONFIG_HOME') or os.path.expanduser('~/.config'),
75+
'pep8'
76+
)
7577
except ImportError:
76-
DEFAULT_CONFIG = None
78+
USER_CONFIG = None
7779

7880
PROJECT_CONFIG = ('setup.cfg', 'tox.ini', '.pep8')
7981
TESTSUITE_PATH = os.path.join(os.path.dirname(__file__), 'testsuite')
@@ -1735,13 +1737,11 @@ def __init__(self, *args, **kwargs):
17351737
# build options from the command line
17361738
self.checker_class = kwargs.pop('checker_class', Checker)
17371739
parse_argv = kwargs.pop('parse_argv', False)
1738-
config_file = kwargs.pop('config_file', None)
17391740
parser = kwargs.pop('parser', None)
17401741
# build options from dict
17411742
options_dict = dict(*args, **kwargs)
17421743
arglist = None if parse_argv else options_dict.get('paths', None)
1743-
options, self.paths = process_options(
1744-
arglist, parse_argv, config_file, parser)
1744+
options, self.paths = process_options(arglist, parse_argv, parser)
17451745
if options_dict:
17461746
options.__dict__.update(options_dict)
17471747
if 'paths' in options_dict:
@@ -1928,17 +1928,22 @@ def read_config(options, args, arglist, parser):
19281928
"""Read both user configuration and local configuration."""
19291929
config = RawConfigParser()
19301930

1931-
user_conf = options.config
1932-
if user_conf and os.path.isfile(user_conf):
1933-
if options.verbose:
1934-
print('user configuration: %s' % user_conf)
1935-
config.read(user_conf)
1931+
cli_conf = options.config
19361932

1933+
if cli_conf and os.path.isfile(cli_conf):
1934+
if options.verbose:
1935+
print('cli configuration: %s' % cli_conf)
1936+
config.read(cli_conf)
19371937
else:
1938+
if USER_CONFIG and os.path.isfile(USER_CONFIG):
1939+
if options.verbose:
1940+
print('user configuration: %s' % USER_CONFIG)
1941+
config.read(USER_CONFIG)
1942+
19381943
local_dir = os.curdir
19391944
parent = tail = args and os.path.abspath(os.path.commonprefix(args))
19401945
while tail:
1941-
if config.read([os.path.join(parent, fn) for fn in PROJECT_CONFIG]):
1946+
if config.read(os.path.join(parent, fn) for fn in PROJECT_CONFIG):
19421947
local_dir = parent
19431948
if options.verbose:
19441949
print('local configuration: in %s' % parent)
@@ -1979,21 +1984,18 @@ def read_config(options, args, arglist, parser):
19791984
return options
19801985

19811986

1982-
def process_options(arglist=None, parse_argv=False, config_file=None,
1983-
parser=None):
1987+
def process_options(arglist=None, parse_argv=False, parser=None):
19841988
"""Process options passed either via arglist or via command line args."""
19851989
if not parser:
19861990
parser = get_parser()
19871991
if not parser.has_option('--config'):
1988-
if config_file is True:
1989-
config_file = DEFAULT_CONFIG
19901992
group = parser.add_option_group("Configuration", description=(
19911993
"The project options are read from the [%s] section of the "
19921994
"tox.ini file or the setup.cfg file located in any parent folder "
19931995
"of the path(s) being processed. Allowed options are: %s." %
19941996
(parser.prog, ', '.join(parser.config_options))))
1995-
group.add_option('--config', metavar='path', default=config_file,
1996-
help="user config file location (default: %default)")
1997+
group.add_option('--config', metavar='path', default=None,
1998+
help="user config file location")
19971999
# Don't read the command line if the module is used as a library.
19982000
if not arglist and not parse_argv:
19992001
arglist = []

0 commit comments

Comments
 (0)