Skip to content

Commit

Permalink
Show logging written to stderr in mypy daemon (#14775)
Browse files Browse the repository at this point in the history
Previously stdout from mypy daemon was propagated to the client, but
some verbose logging is written to stderr and it wasn't propagated. Now
propagate stderr as well. Tested manually.

This builds on top of #13769.
  • Loading branch information
JukkaL authored Feb 24, 2023
1 parent 54635de commit 284142d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mypy/dmypy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,10 +665,15 @@ def request(
return {"error": str(err)}
# TODO: Other errors, e.g. ValueError, UnicodeError
else:
# Display debugging output written to stdout in the server process for convenience.
# Display debugging output written to stdout/stderr in the server process for convenience.
stdout = response.get("stdout")
if stdout:
sys.stdout.write(stdout)
stderr = response.get("stderr")
if stderr:
print("-" * 79)
print("stderr:")
sys.stdout.write(stderr)
return response


Expand Down
4 changes: 4 additions & 0 deletions mypy/dmypy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ def serve(self) -> None:
with server:
data = receive(server)
debug_stdout = io.StringIO()
debug_stderr = io.StringIO()
sys.stdout = debug_stdout
sys.stderr = debug_stderr
resp: dict[str, Any] = {}
if "command" not in data:
resp = {"error": "No command found in request"}
Expand All @@ -233,9 +235,11 @@ def serve(self) -> None:
resp = {"error": "Daemon crashed!\n" + "".join(tb)}
resp.update(self._response_metadata())
resp["stdout"] = debug_stdout.getvalue()
resp["stderr"] = debug_stderr.getvalue()
server.write(json.dumps(resp).encode("utf8"))
raise
resp["stdout"] = debug_stdout.getvalue()
resp["stderr"] = debug_stderr.getvalue()
try:
resp.update(self._response_metadata())
server.write(json.dumps(resp).encode("utf8"))
Expand Down

0 comments on commit 284142d

Please sign in to comment.