Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dmypy run when no target given #6153

Merged
merged 8 commits into from
Jan 8, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Respond to review
emmatyping committed Jan 8, 2019

Verified

This commit was signed with the committer’s verified signature.
emmatyping Emma Smith
commit 35b836ebec57b34855b92b673cbcc3996134c462
2 changes: 0 additions & 2 deletions mypy/dmypy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Client for mypy daemon mode.

Experimental!

This manages a daemon process which keeps useful state in memory
rather than having to read it back from disk on each run.
"""
20 changes: 11 additions & 9 deletions mypy/dmypy_server.py
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@
from mypy.modulefinder import BuildSource, compute_search_paths
from mypy.options import Options
from mypy.typestate import reset_global_state
from mypy.util import redirect_stderr
from mypy.util import redirect_stderr, redirect_stdout
from mypy.version import __version__


@@ -274,14 +274,16 @@ def cmd_run(self, version: str, args: Sequence[str]) -> Dict[str, object]:
# Process options can exit on improper arguments, so we need to catch that and
# capture stderr so the client can report it
stderr = io.StringIO()
stdout = io.StringIO()
with redirect_stderr(stderr):
sources, options = mypy.main.process_options(
['-i'] + list(args),
require_targets=True,
server_options=True,
fscache=self.fscache,
program='dmypy',
header=argparse.SUPPRESS)
with redirect_stdout(stdout):
sources, options = mypy.main.process_options(
['-i'] + list(args),
require_targets=True,
server_options=True,
fscache=self.fscache,
program='mypy-daemon',
header=argparse.SUPPRESS)
# Signal that we need to restart if the options have changed
if self.options_snapshot != options.snapshot():
return {'restart': 'configuration changed'}
@@ -296,7 +298,7 @@ def cmd_run(self, version: str, args: Sequence[str]) -> Dict[str, object]:
except InvalidSourceList as err:
return {'out': '', 'err': str(err), 'status': 2}
except SystemExit as e:
return {'out': '', 'err': stderr.getvalue(), 'status': e.code}
return {'out': stdout.getvalue(), 'err': stderr.getvalue(), 'status': e.code}
return self.check(sources)

def cmd_check(self, files: Sequence[str]) -> Dict[str, object]:
1 change: 1 addition & 0 deletions mypy/util.py
Original file line number Diff line number Diff line change
@@ -260,6 +260,7 @@ def hard_exit(status: int = 0) -> None:


# The following is a backport of stream redirect utilities from Lib/contextlib.py
emmatyping marked this conversation as resolved.
Show resolved Hide resolved
# We need this for 3.4 support. They can be removed in March 2019!


class _RedirectStream:
2 changes: 1 addition & 1 deletion test-data/unit/daemon.test
Original file line number Diff line number Diff line change
@@ -126,7 +126,7 @@ pass
[case testDaemonRunNoTarget]
$ dmypy run -- --follow-imports=error
Daemon started
dmypy: error: Missing target module, package, files, or command.
mypy-daemon: error: Missing target module, package, files, or command.
== Return code: 2
$ dmypy stop
Daemon stopped