From c81b276c1cf0a67e0eb2db51037fa0740bf0d332 Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Mon, 21 May 2018 12:34:33 -0400 Subject: [PATCH] mypy: Add basic support for invoking dmypy to run-mypy. --- .gitignore | 2 ++ tools/run-mypy | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index a86fcf25d18c1..51e99333d91ee 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,8 @@ package-lock.json /.vagrant /var +/.dmypy.json + # Dockerfiles generated for CircleCI /tools/circleci/images diff --git a/tools/run-mypy b/tools/run-mypy index b60f5f8162753..737c5d4cab77c 100755 --- a/tools/run-mypy +++ b/tools/run-mypy @@ -27,6 +27,8 @@ 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', + help="Start and run the mypy fine-grained incremental daemon") parser.add_argument('--scripts-only', action='store_true', help="only check extensionless python scripts") parser.add_argument('-a', '--all', action='store_true', @@ -44,13 +46,15 @@ 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" + # Use zulip-py3-venv's mypy if it's available. VENV_DIR = "/srv/zulip-py3-venv" -MYPY_VENV_PATH = os.path.join(VENV_DIR, "bin", "mypy") +MYPY_VENV_PATH = os.path.join(VENV_DIR, "bin", command_name) if os.path.exists(MYPY_VENV_PATH): mypy_command = MYPY_VENV_PATH else: - mypy_command = "mypy" + mypy_command = command_name if args.version: print("mypy command:", mypy_command) @@ -79,7 +83,11 @@ if args.linecoverage_report: if args.quick: extra_args.append("--quick") -rc = subprocess.call([mypy_command] + extra_args + python_files + pyi_files) +mypy_args = extra_args + python_files + pyi_files +if args.daemon: + rc = subprocess.call([mypy_command, 'run', '--'] + mypy_args) +else: + rc = subprocess.call([mypy_command] + mypy_args) if args.linecoverage_report: # Move the coverage report to where codecov will look for it.