11# Copyright 2019 Palantir Technologies, Inc.
22"""Linter pluging for flake8"""
33import logging
4+ from os import path
45import re
56from subprocess import Popen , PIPE
67from pyls import hookimpl , lsp
@@ -20,6 +21,7 @@ def pyls_lint(config, document):
2021 log .debug ("Got flake8 settings: %s" , settings )
2122
2223 opts = {
24+ 'config' : settings .get ('config' ),
2325 'exclude' : settings .get ('exclude' ),
2426 'filename' : settings .get ('filename' ),
2527 'hang-closing' : settings .get ('hangClosing' ),
@@ -28,6 +30,14 @@ def pyls_lint(config, document):
2830 'select' : settings .get ('select' ),
2931 }
3032
33+ # flake takes only absolute path to the config. So we should check and
34+ # convert if necessary
35+ if opts .get ('config' ) and not path .isabs (opts .get ('config' )):
36+ opts ['config' ] = path .abspath (path .expanduser (path .expandvars (
37+ opts .get ('config' )
38+ )))
39+ log .debug ("using flake8 with config: %s" , opts ['config' ])
40+
3141 # Call the flake8 utility then parse diagnostics from stdout
3242 args = build_args (opts , document .path )
3343 output = run_flake8 (args )
@@ -64,16 +74,17 @@ def build_args(options, doc_path):
6474 """
6575 args = [doc_path ]
6676 for arg_name , arg_val in options .items ():
77+ if arg_val is None :
78+ continue
6779 arg = None
6880 if isinstance (arg_val , list ):
6981 arg = '--{}={}' .format (arg_name , ',' .join (arg_val ))
7082 elif isinstance (arg_val , bool ):
7183 if arg_val :
7284 arg = '--{}' .format (arg_name )
73- elif isinstance ( arg_val , int ) :
85+ else :
7486 arg = '--{}={}' .format (arg_name , arg_val )
75- if arg :
76- args .append (arg )
87+ args .append (arg )
7788 return args
7889
7990
0 commit comments