Files
upstream-zulip/tools/run-mypy
upstream-mirror 64898b2c79
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
2026-09-15 15:05:30 +05:00

80 lines
2.4 KiB
Python
Executable File

#!/usr/bin/env python3
import argparse
import os
import subprocess
import sys
from zulint import lister
TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
ROOT_DIR = os.path.dirname(TOOLS_DIR)
os.chdir(ROOT_DIR)
sys.path.append(ROOT_DIR)
from tools.lib.test_script import add_provision_check_override_param, assert_provisioning_status_ok
exclude = [
"stubs/",
]
parser = argparse.ArgumentParser(description="Run mypy on files tracked by git.")
parser.add_argument("targets", nargs="*", help="files and directories to check (default: .)")
parser.add_argument("--version", action="store_true", help="show mypy version information and exit")
parser.add_argument("-m", "--modified", action="store_true", help="check only modified files")
parser.add_argument(
"--scripts-only", action="store_true", help="only check extensionless python scripts"
)
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:
mypy_command = "dmypy"
else:
mypy_command = "mypy"
if args.version:
print("mypy command:", mypy_command)
sys.exit(subprocess.call([mypy_command, "--version"]))
if args.all:
exclude = []
# find all non-excluded files in current directory
files_dict = lister.list_files(
targets=args.targets,
ftypes=["py", "pyi"],
use_shebang=True,
modified_only=args.modified,
exclude=exclude,
group_by_ftype=True,
extless_only=args.scripts_only,
)
pyi_files = list(files_dict["pyi"])
python_files = [
fpath for fpath in files_dict["py"] if not fpath.endswith(".py") or fpath + "i" not in pyi_files
]
if not python_files and not pyi_files:
print("There are no files to run mypy on.")
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]
rc = subprocess.call([mypy_command, *mypy_args])
if rc != 0:
print()
print("See https://zulip.readthedocs.io/en/latest/testing/mypy.html for debugging tips.")
sys.exit(rc)