mirror of https://github.com/zulip/zulip.git
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 <p359101898@gmail.com>
This commit is contained in:
parent
ea3478e377
commit
bf9f9c8b5d
|
@ -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",
|
||||
|
|
|
@ -28,11 +28,15 @@ 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)
|
||||
|
||||
if args.use_daemon:
|
||||
command_name = "dmypy"
|
||||
else:
|
||||
command_name = "mypy"
|
||||
|
||||
# Use zulip-py3-venv's mypy if it's available.
|
||||
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue