From 1c26a828fe41c349a79b6e97e4024c5e0a4070ae Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Fri, 2 Oct 2020 15:04:23 -0500 Subject: [PATCH 1/2] Resolve flake8_executable allowing ~/${HOME} paths --- pyls/plugins/flake8_lint.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pyls/plugins/flake8_lint.py b/pyls/plugins/flake8_lint.py index 6189727b..ce8f1b31 100644 --- a/pyls/plugins/flake8_lint.py +++ b/pyls/plugins/flake8_lint.py @@ -1,7 +1,7 @@ # Copyright 2019 Palantir Technologies, Inc. """Linter pluging for flake8""" import logging -from os import path +import os.path import re from subprocess import Popen, PIPE from pyls import hookimpl, lsp @@ -34,8 +34,8 @@ def pyls_lint(workspace, document): # flake takes only absolute path to the config. So we should check and # convert if necessary - if opts.get('config') and not path.isabs(opts.get('config')): - opts['config'] = path.abspath(path.expanduser(path.expandvars( + if opts.get('config') and not os.path.isabs(opts.get('config')): + opts['config'] = os.path.abspath(os.path.expanduser(os.path.expandvars( opts.get('config') ))) log.debug("using flake8 with config: %s", opts['config']) @@ -56,6 +56,12 @@ def run_flake8(flake8_executable, args, document): args = [(i if not i.startswith('--ignore=') else FIX_IGNORES_RE.sub('', i)) for i in args if i is not None] + # if executable looks like a path resolve it + if os.sep in flake8_executable: + flake8_executable = os.path.abspath( + os.path.expanduser(os.path.expandvars(flake8_executable)) + ) + log.debug("Calling %s with args: '%s'", flake8_executable, args) try: cmd = [flake8_executable] From 91773bd659004889cc7849e2ad40c7150cdeff55 Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Sat, 3 Oct 2020 10:05:26 -0500 Subject: [PATCH 2/2] Only resolve path if not found Co-authored-by: Carlos Cordoba --- pyls/plugins/flake8_lint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyls/plugins/flake8_lint.py b/pyls/plugins/flake8_lint.py index ce8f1b31..d218e91f 100644 --- a/pyls/plugins/flake8_lint.py +++ b/pyls/plugins/flake8_lint.py @@ -57,7 +57,7 @@ def run_flake8(flake8_executable, args, document): for i in args if i is not None] # if executable looks like a path resolve it - if os.sep in flake8_executable: + if not os.path.isfile(flake8_executable) and os.sep in flake8_executable: flake8_executable = os.path.abspath( os.path.expanduser(os.path.expandvars(flake8_executable)) )