Skip to content

Add configurable flake8 executable #821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions pyls/plugins/flake8_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,28 @@ def pyls_lint(workspace, document):
log.debug("using flake8 with config: %s", opts['config'])

# Call the flake8 utility then parse diagnostics from stdout
flake8_executable = settings.get('executable', 'flake8')

args = build_args(opts, document.path)
output = run_flake8(args)
output = run_flake8(flake8_executable, args)
return parse_stdout(document, output)


def run_flake8(args):
def run_flake8(flake8_executable, args):
"""Run flake8 with the provided arguments, logs errors
from stderr if any.
"""
# a quick temporary fix to deal with Atom
args = [(i if not i.startswith('--ignore=') else FIX_IGNORES_RE.sub('', i))
for i in args if i is not None]
log.debug("Calling flake8 with args: '%s'", args)

log.debug("Calling %s with args: '%s'", flake8_executable, args)
try:
cmd = ['flake8']
cmd = [flake8_executable]
cmd.extend(args)
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
except IOError:
log.debug("Can't execute flake8. Trying with 'python -m flake8'")
log.debug("Can't execute %s. Trying with 'python -m flake8'", flake8_executable)
cmd = ['python', '-m', 'flake8']
cmd.extend(args)
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
Expand Down
15 changes: 15 additions & 0 deletions test/plugins/test_flake8_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,18 @@ def test_flake8_config_param(workspace):
call_args = popen_mock.call_args.args[0]
assert 'flake8' in call_args
assert '--config={}'.format(flake8_conf) in call_args


def test_flake8_executable_param(workspace):
with patch('pyls.plugins.flake8_lint.Popen') as popen_mock:
mock_instance = popen_mock.return_value
mock_instance.communicate.return_value = [bytes(), bytes()]

flake8_executable = '/tmp/flake8'
workspace._config.update({'plugins': {'flake8': {'executable': flake8_executable}}})

_name, doc = temp_document(DOC, workspace)
flake8_lint.pyls_lint(workspace, doc)

call_args = popen_mock.call_args.args[0]
assert flake8_executable in call_args