Skip to content

Commit 1dfe443

Browse files
committed
Suppress pep8 error output when there's no config.
When no pep8 config file is found, OptionParser.error() raises a SystemExit and prints usage output; we don't need this output, so this commit supresses it. Related to issue #3.
1 parent 3af192d commit 1dfe443

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

linter.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,15 @@ def check(self, code, filename):
6060
# Try to read options from pep8 default configuration files (.pep8, tox.ini).
6161
# If present, they will override the ones defined by Sublime Linter's config.
6262
try:
63-
from pep8 import process_options
64-
pep8_options, _ = process_options([], True, True, None)
63+
# `onError` will be called by `process_options` when no pep8 configuration file is found.
64+
# Override needed to supress OptionParser.error() output in the default parser.
65+
def onError(msg):
66+
raise SystemExit
67+
68+
from pep8 import process_options, get_parser
69+
parser = get_parser()
70+
parser.error = onError
71+
pep8_options, _ = process_options([], True, True, parser=parser)
6572
pep8_options = vars(pep8_options)
6673
del pep8_options['reporter']
6774
for opt_n, opt_v in pep8_options.items():

0 commit comments

Comments
 (0)