Skip to content

Commit 3af192d

Browse files
committed
Read pep8 configuration files (.pep8, tox.ini, ...)
Implements feature in issue #3.
1 parent ca46626 commit 3af192d

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

linter.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,29 @@ def check(self, code, filename):
5555

5656
self.build_options(options, type_map, transform=lambda s: s.replace('-', '_'))
5757

58+
final_options = options.copy()
59+
60+
# Try to read options from pep8 default configuration files (.pep8, tox.ini).
61+
# If present, they will override the ones defined by Sublime Linter's config.
62+
try:
63+
from pep8 import process_options
64+
pep8_options, _ = process_options([], True, True, None)
65+
pep8_options = vars(pep8_options)
66+
del pep8_options['reporter']
67+
for opt_n, opt_v in pep8_options.items():
68+
if isinstance(final_options.get(opt_n, None), list):
69+
final_options[opt_n] += opt_v
70+
else:
71+
final_options[opt_n] = opt_v
72+
except SystemExit:
73+
# Catch and ignore parser.error() when no config files are found.
74+
pass
75+
5876
if persist.debug_mode():
59-
persist.printf('{} options: {}'.format(self.name, options))
77+
persist.printf('{} ST options: {}'.format(self.name, options))
78+
persist.printf('{} options: {}'.format(self.name, final_options))
6079

61-
checker = self.module.StyleGuide(**options)
80+
checker = self.module.StyleGuide(**final_options)
6281

6382
return checker.input_file(
6483
filename=os.path.basename(filename),

0 commit comments

Comments
 (0)