Skip to content

Commit 42491d8

Browse files
committed
Use subprocess to execute mypy / dmypy
Fixes #17
1 parent 12cdaa1 commit 42491d8

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

pylsp_mypy/plugin.py

Lines changed: 11 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,28 @@ 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(["mypy", *args], capture_output=True)
194+
report = completed_process.stdout.decode()
195+
errors = completed_process.stderr.decode()
194196
else:
195197
# If dmypy daemon is non-responsive calls to run will block.
196198
# Check daemon status, if non-zero daemon is dead or hung.
197199
# If daemon is hung, kill will reset
198200
# If daemon is dead/absent, kill will no-op.
199201
# In either case, reset to fresh state
200-
_, _err, _status = mypy_api.run_dmypy(["status"])
202+
completed_process = subprocess.run(["dmypy", *args], capture_output=True)
203+
_err = completed_process.stderr.decode()
204+
_status = completed_process.returncode
201205
if _status != 0:
202206
log.info("restarting dmypy from status: %s message: %s", _status, _err.strip())
203-
mypy_api.run_dmypy(["kill"])
207+
subprocess.run(["dmypy", "kill"])
204208

205209
# run to use existing daemon or restart if required
206210
args = ["run", "--"] + args
207211
log.info("dmypy run args = %s", args)
208-
report, errors, _ = mypy_api.run_dmypy(args)
212+
completed_process = subprocess.run(["dmypy", *args], capture_output=True)
213+
report = completed_process.stdout.decode()
214+
errors = completed_process.stderr.decode()
209215

210216
log.debug("report:\n%s", report)
211217
log.debug("errors:\n%s", errors)

0 commit comments

Comments
 (0)