@@ -43,12 +43,12 @@ def pyls_lint(workspace, document):
43
43
# Call the flake8 utility then parse diagnostics from stdout
44
44
flake8_executable = settings .get ('executable' , 'flake8' )
45
45
46
- args = build_args (opts , document . path )
47
- output = run_flake8 (flake8_executable , args )
46
+ args = build_args (opts )
47
+ output = run_flake8 (flake8_executable , args , document )
48
48
return parse_stdout (document , output )
49
49
50
50
51
- def run_flake8 (flake8_executable , args ):
51
+ def run_flake8 (flake8_executable , args , document ):
52
52
"""Run flake8 with the provided arguments, logs errors
53
53
from stderr if any.
54
54
"""
@@ -60,26 +60,25 @@ def run_flake8(flake8_executable, args):
60
60
try :
61
61
cmd = [flake8_executable ]
62
62
cmd .extend (args )
63
- p = Popen (cmd , stdout = PIPE , stderr = PIPE )
63
+ p = Popen (cmd , stdin = PIPE , stdout = PIPE , stderr = PIPE )
64
64
except IOError :
65
65
log .debug ("Can't execute %s. Trying with 'python -m flake8'" , flake8_executable )
66
66
cmd = ['python' , '-m' , 'flake8' ]
67
67
cmd .extend (args )
68
- p = Popen (cmd , stdout = PIPE , stderr = PIPE )
69
- (stdout , stderr ) = p .communicate ()
68
+ p = Popen (cmd , stdin = PIPE , stdout = PIPE , stderr = PIPE )
69
+ (stdout , stderr ) = p .communicate (document . source . encode () )
70
70
if stderr :
71
71
log .error ("Error while running flake8 '%s'" , stderr .decode ())
72
72
return stdout .decode ()
73
73
74
74
75
- def build_args (options , doc_path ):
75
+ def build_args (options ):
76
76
"""Build arguments for calling flake8.
77
77
78
78
Args:
79
79
options: dictionary of argument names and their values.
80
- doc_path: path of the document to lint.
81
80
"""
82
- args = [doc_path ]
81
+ args = ['-' ] # use stdin
83
82
for arg_name , arg_val in options .items ():
84
83
if arg_val is None :
85
84
continue
0 commit comments