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]