From f3c6d91e69d88b86c13e5d1c6ba979e45bdd4354 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Sun, 16 Dec 2018 20:49:33 -0800 Subject: [PATCH] mypy: Switch default to daemon mode. There isn't any real advantage to running the non-daemon mode at this point. --- docs/contributing/mypy.md | 18 +++++++----------- tools/ci/backend | 4 +++- tools/run-mypy | 10 +++++----- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/docs/contributing/mypy.md b/docs/contributing/mypy.md index 849e0b8180..b7afd4b53c 100644 --- a/docs/contributing/mypy.md +++ b/docs/contributing/mypy.md @@ -114,19 +114,15 @@ To run mypy on Zulip's python code, you can run the command: tools/run-mypy -You can also run mypy as a long-running daemon (server) process and send -type-checking requests to the server via the command: +This will take a while to start running, since it runs mypy as a +long-running daemon (server) process and send type-checking requests +to the server; this makes checking mypy about 100x faster. But if +you're debugging or for whatever reason don't want the daemon, you can +use: - tools/run-mypy -d + tools/run-mypy --no-daemon -While the mypy daemon is experimental and currently supports macOS and Linux -only, **we strongly recommend using the daemon** if it is an option. Program -state from previous runs will be cached in memory and will not have to be -read from the file system on each run. For a large codebase like Zulip's -and a workflow involving running mypy repeatedly after small edits, using -the daemon can be *10 or more times faster*. - -Mypy will output errors in the same style as a compiler would. For +Mypy outputs errors in the same style as a compiler would. For example, if your code has a type error like this: ``` diff --git a/tools/ci/backend b/tools/ci/backend index 35e24295be..2b2de42ba5 100755 --- a/tools/ci/backend +++ b/tools/ci/backend @@ -13,7 +13,9 @@ set -x # We run mypy after the backend tests so we get output from the # backend tests, which tend to uncover more serious problems, first. ./tools/run-mypy --version -./tools/run-mypy +# We run mypy without daemon mode, since that's faster given that +# we're only going to run it once. +./tools/run-mypy --no-daemon ./tools/test-migrations ./tools/setup/optimize-svg diff --git a/tools/run-mypy b/tools/run-mypy index 7a0d3150a8..c90789719c 100755 --- a/tools/run-mypy +++ b/tools/run-mypy @@ -28,7 +28,7 @@ parser.add_argument('--quick', action='store_true', help="pass --quick to mypy") parser.add_argument('-m', '--modified', action='store_true', help="check only modified files") -parser.add_argument('-d', '--daemon', action='store_true', +parser.add_argument('--no-daemon', action='store_true', help="Start and run the mypy fine-grained incremental daemon") parser.add_argument('--scripts-only', action='store_true', help="only check extensionless python scripts") @@ -45,7 +45,7 @@ if not args.force: print('If you really know what you are doing, use --force to run anyway.') sys.exit(1) -command_name = "mypy" if not args.daemon else "dmypy" +command_name = "mypy" if (args.no_daemon or args.version) else "dmypy" # Use zulip-py3-venv's mypy if it's available. VENV_DIR = "/srv/zulip-py3-venv" @@ -80,10 +80,10 @@ if args.quick: extra_args.append("--quick") mypy_args = extra_args + python_files + pyi_files -if args.daemon: - rc = subprocess.call([mypy_command, 'run', '--'] + mypy_args) -else: +if args.no_daemon: rc = subprocess.call([mypy_command] + mypy_args) +else: + rc = subprocess.call([mypy_command, 'run', '--'] + mypy_args) if rc != 0: print("")