Skip to content

Commit ee9c279

Browse files
authored
Merge pull request #591 from daspecster/support-pep8-pycodestyle-config
Check for both [pep8] and [pycodestyle] config sections.
2 parents 5c4ca67 + 2cc7a8a commit ee9c279

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

pycodestyle.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import sys
5656
import time
5757
import tokenize
58+
import warnings
5859

5960
from fnmatch import fnmatch
6061
from optparse import OptionParser
@@ -2144,29 +2145,36 @@ def read_config(options, args, arglist, parser):
21442145
print('cli configuration: %s' % cli_conf)
21452146
config.read(cli_conf)
21462147

2147-
pep8_section = parser.prog
2148-
if config.has_section(pep8_section):
2148+
pycodestyle_section = None
2149+
if config.has_section(parser.prog):
2150+
pycodestyle_section = parser.prog
2151+
elif config.has_section('pep8'):
2152+
pycodestyle_section = 'pep8' # Deprecated
2153+
warnings.warn('[pep8] section is deprecated. Use [pycodestyle].')
2154+
2155+
if pycodestyle_section:
21492156
option_list = dict([(o.dest, o.type or o.action)
21502157
for o in parser.option_list])
21512158

21522159
# First, read the default values
21532160
(new_options, __) = parser.parse_args([])
21542161

21552162
# Second, parse the configuration
2156-
for opt in config.options(pep8_section):
2163+
for opt in config.options(pycodestyle_section):
21572164
if opt.replace('_', '-') not in parser.config_options:
21582165
print(" unknown option '%s' ignored" % opt)
21592166
continue
21602167
if options.verbose > 1:
2161-
print(" %s = %s" % (opt, config.get(pep8_section, opt)))
2168+
print(" %s = %s" % (opt,
2169+
config.get(pycodestyle_section, opt)))
21622170
normalized_opt = opt.replace('-', '_')
21632171
opt_type = option_list[normalized_opt]
21642172
if opt_type in ('int', 'count'):
2165-
value = config.getint(pep8_section, opt)
2173+
value = config.getint(pycodestyle_section, opt)
21662174
elif opt_type in ('store_true', 'store_false'):
2167-
value = config.getboolean(pep8_section, opt)
2175+
value = config.getboolean(pycodestyle_section, opt)
21682176
else:
2169-
value = config.get(pep8_section, opt)
2177+
value = config.get(pycodestyle_section, opt)
21702178
if normalized_opt == 'exclude':
21712179
value = normalize_paths(value, local_dir)
21722180
setattr(new_options, normalized_opt, value)

0 commit comments

Comments
 (0)