Skip to content

Commit a9b55f4

Browse files
committed
mypy: Run mypy for each package separately.
1 parent 188535d commit a9b55f4

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

tools/run-mypy

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import sys
88
import argparse
99
import subprocess
1010

11+
from collections import OrderedDict
12+
from pathlib import PurePath
13+
1114
import lister
1215
from typing import cast, Dict, List
1316

@@ -42,11 +45,8 @@ zulip_botserver/zulip_botserver/server.py
4245
zulip_botserver/setup.py
4346
""".split()
4447

45-
default_targets = ['zulip/zulip',
46-
'zulip/setup.py']
47-
4848
parser = argparse.ArgumentParser(description="Run mypy on files tracked by git.")
49-
parser.add_argument('targets', nargs='*', default=default_targets,
49+
parser.add_argument('targets', nargs='*', default=[],
5050
help="""files and directories to include in the result.
5151
If this is not specified, the current directory is used""")
5252
parser.add_argument('-m', '--modified', action='store_true', default=False, help='list only modified files')
@@ -80,6 +80,12 @@ pyi_files = set(files_dict['pyi'])
8080
python_files = [fpath for fpath in files_dict['py']
8181
if not fpath.endswith('.py') or fpath + 'i' not in pyi_files]
8282

83+
repo_python_files = OrderedDict([('zulip', []), ('zulip_bots', []), ('zulip_botserver', [])])
84+
for file_path in python_files:
85+
repo = PurePath(file_path).parts[0]
86+
if repo in repo_python_files:
87+
repo_python_files[repo].append(file_path)
88+
8389
mypy_command = "mypy"
8490

8591
extra_args = ["--check-untyped-defs",
@@ -98,8 +104,11 @@ if args.quick:
98104
extra_args.append("--quick")
99105

100106
# run mypy
101-
if python_files:
102-
rc = subprocess.call([mypy_command] + extra_args + python_files)
103-
sys.exit(rc)
104-
else:
105-
print("There are no files to run mypy on.")
107+
for repo, python_files in repo_python_files.items():
108+
print("Running mypy for `{}`.".format(repo))
109+
if python_files:
110+
rc = subprocess.call([mypy_command] + extra_args + python_files)
111+
if rc:
112+
sys.exit(rc)
113+
else:
114+
print("There are no files to run mypy on.")

0 commit comments

Comments
 (0)