Skip to content

Commit 5fa7ae9

Browse files
authored
Add configurable flake8 executable (#821)
1 parent 4646633 commit 5fa7ae9

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

pyls/plugins/flake8_lint.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,28 @@ def pyls_lint(workspace, document):
4141
log.debug("using flake8 with config: %s", opts['config'])
4242

4343
# Call the flake8 utility then parse diagnostics from stdout
44+
flake8_executable = settings.get('executable', 'flake8')
45+
4446
args = build_args(opts, document.path)
45-
output = run_flake8(args)
47+
output = run_flake8(flake8_executable, args)
4648
return parse_stdout(document, output)
4749

4850

49-
def run_flake8(args):
51+
def run_flake8(flake8_executable, args):
5052
"""Run flake8 with the provided arguments, logs errors
5153
from stderr if any.
5254
"""
5355
# a quick temporary fix to deal with Atom
5456
args = [(i if not i.startswith('--ignore=') else FIX_IGNORES_RE.sub('', i))
5557
for i in args if i is not None]
56-
log.debug("Calling flake8 with args: '%s'", args)
58+
59+
log.debug("Calling %s with args: '%s'", flake8_executable, args)
5760
try:
58-
cmd = ['flake8']
61+
cmd = [flake8_executable]
5962
cmd.extend(args)
6063
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
6164
except IOError:
62-
log.debug("Can't execute flake8. Trying with 'python -m flake8'")
65+
log.debug("Can't execute %s. Trying with 'python -m flake8'", flake8_executable)
6366
cmd = ['python', '-m', 'flake8']
6467
cmd.extend(args)
6568
p = Popen(cmd, stdout=PIPE, stderr=PIPE)

test/plugins/test_flake8_lint.py

+15
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,18 @@ def test_flake8_config_param(workspace):
6565
call_args = popen_mock.call_args.args[0]
6666
assert 'flake8' in call_args
6767
assert '--config={}'.format(flake8_conf) in call_args
68+
69+
70+
def test_flake8_executable_param(workspace):
71+
with patch('pyls.plugins.flake8_lint.Popen') as popen_mock:
72+
mock_instance = popen_mock.return_value
73+
mock_instance.communicate.return_value = [bytes(), bytes()]
74+
75+
flake8_executable = '/tmp/flake8'
76+
workspace._config.update({'plugins': {'flake8': {'executable': flake8_executable}}})
77+
78+
_name, doc = temp_document(DOC, workspace)
79+
flake8_lint.pyls_lint(workspace, doc)
80+
81+
call_args = popen_mock.call_args.args[0]
82+
assert flake8_executable in call_args

0 commit comments

Comments
 (0)