1
1
# Copyright 2019 Palantir Technologies, Inc.
2
2
"""Linter pluging for flake8"""
3
3
import logging
4
+ from os import path
4
5
import re
5
6
from subprocess import Popen , PIPE
6
7
from pyls import hookimpl , lsp
@@ -20,6 +21,7 @@ def pyls_lint(config, document):
20
21
log .debug ("Got flake8 settings: %s" , settings )
21
22
22
23
opts = {
24
+ 'config' : settings .get ('config' ),
23
25
'exclude' : settings .get ('exclude' ),
24
26
'filename' : settings .get ('filename' ),
25
27
'hang-closing' : settings .get ('hangClosing' ),
@@ -28,6 +30,14 @@ def pyls_lint(config, document):
28
30
'select' : settings .get ('select' ),
29
31
}
30
32
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
+
31
41
# Call the flake8 utility then parse diagnostics from stdout
32
42
args = build_args (opts , document .path )
33
43
output = run_flake8 (args )
@@ -64,16 +74,17 @@ def build_args(options, doc_path):
64
74
"""
65
75
args = [doc_path ]
66
76
for arg_name , arg_val in options .items ():
77
+ if arg_val is None :
78
+ continue
67
79
arg = None
68
80
if isinstance (arg_val , list ):
69
81
arg = '--{}={}' .format (arg_name , ',' .join (arg_val ))
70
82
elif isinstance (arg_val , bool ):
71
83
if arg_val :
72
84
arg = '--{}' .format (arg_name )
73
- elif isinstance ( arg_val , int ) :
85
+ else :
74
86
arg = '--{}={}' .format (arg_name , arg_val )
75
- if arg :
76
- args .append (arg )
87
+ args .append (arg )
77
88
return args
78
89
79
90
0 commit comments