From bf9f9c8b5dbefe6db51483e509ab6ba2c2988aff Mon Sep 17 00:00:00 2001 From: Zixuan James Li Date: Tue, 28 Jun 2022 14:12:35 -0400 Subject: [PATCH] tools: Support running mypy daemon for better performance. mypy daemon performs significantly better than running the regular mypy cli tool when we type check the entire codebase multiple times locally. This adds running mypy daemon as an option for both `tools/run-mypy` and `tools/lint`. To ensure daemon messages like "Daemon started", "Daemon stopped" won't get printed we filter any output that starts with "Daemon". Signed-off-by: Zixuan James Li --- tools/lint | 8 ++++++++ tools/run-mypy | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/lint b/tools/lint index ffa85b2935..4fcd23d520 100755 --- a/tools/lint +++ b/tools/lint @@ -31,6 +31,7 @@ def run() -> None: parser = argparse.ArgumentParser() add_provision_check_override_param(parser) parser.add_argument("--full", action="store_true", help="Check some things we typically ignore") + parser.add_argument("--use-mypy-daemon", action="store_true", help="Run mypy daemon instead") add_default_linter_arguments(parser) args = parser.parse_args() @@ -131,12 +132,19 @@ def run() -> None: command = ["tools/run-mypy", "--quiet"] if args.skip_provision_check: command.append("--skip-provision-check") + if args.use_mypy_daemon: + command.append("--use-daemon") linter_config.external_linter( "mypy", command, ["py", "pyi"], pass_targets=False, description="Static type checker for Python (config: pyproject.toml)", + suppress_line=( + lambda line: line.startswith("Daemon") or line == "Restarting: configuration changed" + ) + if args.use_mypy_daemon + else lambda _: False, ) linter_config.external_linter( "tsc", diff --git a/tools/run-mypy b/tools/run-mypy index d96a1a1023..88d4991867 100755 --- a/tools/run-mypy +++ b/tools/run-mypy @@ -28,12 +28,16 @@ parser.add_argument( parser.add_argument( "-a", "--all", action="store_true", help="check all files, bypassing the default exclude list" ) +parser.add_argument("-d", "--use-daemon", action="store_true", help="run mypy daemon instead") add_provision_check_override_param(parser) parser.add_argument("--quiet", action="store_true", help="suppress mypy summary output") args = parser.parse_args() assert_provisioning_status_ok(args.skip_provision_check) -command_name = "mypy" +if args.use_daemon: + command_name = "dmypy" +else: + command_name = "mypy" # Use zulip-py3-venv's mypy if it's available. VENV_DIR = "/srv/zulip-py3-venv" @@ -69,6 +73,9 @@ if not python_files and not pyi_files: sys.exit(0) mypy_args: List[str] = [] +# --no-error-summary is a mypy flag that comes after all dmypy options +if args.use_daemon: + mypy_args += ["run", "--"] if args.quiet: mypy_args += ["--no-error-summary"] mypy_args += ["--", *python_files, *pyi_files]