Skip to content

Commit 518c316

Browse files
authored
Merge pull request #23 from meshy/use-subprocess-to-run-mypy
Fix virtualenv detection by using subprocess to execute mypy / dmypy
2 parents 102f495 + d0e35fe commit 518c316

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

pylsp_mypy/plugin.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import tempfile
1111
import os
1212
import os.path
13+
import subprocess
1314
from pathlib import Path
1415
import logging
15-
from mypy import api as mypy_api
1616
from pylsp import hookimpl
1717
from pylsp.workspace import Document, Workspace
1818
from pylsp.config.config import Config
@@ -190,22 +190,32 @@ def pylsp_lint(
190190
args.extend(["--incremental", "--follow-imports", "silent"])
191191

192192
log.info("executing mypy args = %s", args)
193-
report, errors, _ = mypy_api.run(args)
193+
completed_process = subprocess.run(
194+
["mypy", *args], stdout=subprocess.PIPE, stderr=subprocess.PIPE
195+
)
196+
report = completed_process.stdout.decode()
197+
errors = completed_process.stderr.decode()
194198
else:
195199
# If dmypy daemon is non-responsive calls to run will block.
196200
# Check daemon status, if non-zero daemon is dead or hung.
197201
# If daemon is hung, kill will reset
198202
# If daemon is dead/absent, kill will no-op.
199203
# In either case, reset to fresh state
200-
_, _err, _status = mypy_api.run_dmypy(["status"])
204+
completed_process = subprocess.run(["dmypy", *args], stderr=subprocess.PIPE)
205+
_err = completed_process.stderr.decode()
206+
_status = completed_process.returncode
201207
if _status != 0:
202208
log.info("restarting dmypy from status: %s message: %s", _status, _err.strip())
203-
mypy_api.run_dmypy(["kill"])
209+
subprocess.run(["dmypy", "kill"])
204210

205211
# run to use existing daemon or restart if required
206212
args = ["run", "--"] + args
207213
log.info("dmypy run args = %s", args)
208-
report, errors, _ = mypy_api.run_dmypy(args)
214+
completed_process = subprocess.run(
215+
["dmypy", *args], stdout=subprocess.PIPE, stderr=subprocess.PIPE
216+
)
217+
report = completed_process.stdout.decode()
218+
errors = completed_process.stderr.decode()
209219

210220
log.debug("report:\n%s", report)
211221
log.debug("errors:\n%s", errors)

0 commit comments

Comments
 (0)