From 5fa7ae9154c79ba1f5347e1452bd770a958869b3 Mon Sep 17 00:00:00 2001 From: Ruhul Alam <3430752+ruhulio@users.noreply.github.com> Date: Tue, 30 Jun 2020 17:30:36 -0500 Subject: [PATCH] Add configurable flake8 executable (#821) --- pyls/plugins/flake8_lint.py | 13 ++++++++----- test/plugins/test_flake8_lint.py | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/pyls/plugins/flake8_lint.py b/pyls/plugins/flake8_lint.py index 4eae5376..addb82cc 100644 --- a/pyls/plugins/flake8_lint.py +++ b/pyls/plugins/flake8_lint.py @@ -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) diff --git a/test/plugins/test_flake8_lint.py b/test/plugins/test_flake8_lint.py index 7c238be8..778a58e0 100644 --- a/test/plugins/test_flake8_lint.py +++ b/test/plugins/test_flake8_lint.py @@ -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