11# Copyright 2019 Palantir Technologies, Inc.
22"""Linter pluging for flake8"""
33import logging
4- from os import path
4+ import os . path
55import re
66from subprocess import Popen , PIPE
77from pyls import hookimpl , lsp
@@ -34,8 +34,8 @@ def pyls_lint(workspace, document):
3434
3535 # flake takes only absolute path to the config. So we should check and
3636 # convert if necessary
37- if opts .get ('config' ) and not path .isabs (opts .get ('config' )):
38- opts ['config' ] = path .abspath (path .expanduser (path .expandvars (
37+ if opts .get ('config' ) and not os . path .isabs (opts .get ('config' )):
38+ opts ['config' ] = os . path .abspath (os . path .expanduser (os . path .expandvars (
3939 opts .get ('config' )
4040 )))
4141 log .debug ("using flake8 with config: %s" , opts ['config' ])
@@ -56,6 +56,12 @@ def run_flake8(flake8_executable, args, document):
5656 args = [(i if not i .startswith ('--ignore=' ) else FIX_IGNORES_RE .sub ('' , i ))
5757 for i in args if i is not None ]
5858
59+ # if executable looks like a path resolve it
60+ if not os .path .isfile (flake8_executable ) and os .sep in flake8_executable :
61+ flake8_executable = os .path .abspath (
62+ os .path .expanduser (os .path .expandvars (flake8_executable ))
63+ )
64+
5965 log .debug ("Calling %s with args: '%s'" , flake8_executable , args )
6066 try :
6167 cmd = [flake8_executable ]
0 commit comments