@@ -43,12 +43,12 @@ def pyls_lint(workspace, document):
4343 # Call the flake8 utility then parse diagnostics from stdout
4444 flake8_executable = settings .get ('executable' , 'flake8' )
4545
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 )
4848 return parse_stdout (document , output )
4949
5050
51- def run_flake8 (flake8_executable , args ):
51+ def run_flake8 (flake8_executable , args , document ):
5252 """Run flake8 with the provided arguments, logs errors
5353 from stderr if any.
5454 """
@@ -60,26 +60,25 @@ def run_flake8(flake8_executable, args):
6060 try :
6161 cmd = [flake8_executable ]
6262 cmd .extend (args )
63- p = Popen (cmd , stdout = PIPE , stderr = PIPE )
63+ p = Popen (cmd , stdin = PIPE , stdout = PIPE , stderr = PIPE )
6464 except IOError :
6565 log .debug ("Can't execute %s. Trying with 'python -m flake8'" , flake8_executable )
6666 cmd = ['python' , '-m' , 'flake8' ]
6767 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 () )
7070 if stderr :
7171 log .error ("Error while running flake8 '%s'" , stderr .decode ())
7272 return stdout .decode ()
7373
7474
75- def build_args (options , doc_path ):
75+ def build_args (options ):
7676 """Build arguments for calling flake8.
7777
7878 Args:
7979 options: dictionary of argument names and their values.
80- doc_path: path of the document to lint.
8180 """
82- args = [doc_path ]
81+ args = ['-' ] # use stdin
8382 for arg_name , arg_val in options .items ():
8483 if arg_val is None :
8584 continue
0 commit comments