Skip to content

Commit 449d5fa

Browse files
roberthoenigtimabbott
authored andcommitted
mypy: Run mypy for each package separately.
1 parent abe9338 commit 449d5fa

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

tools/run-mypy

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

11+
from collections import OrderedDict
12+
from pathlib import PurePath
1113
from server_lib import lister
1214
from typing import cast, Dict, List
1315

@@ -42,11 +44,8 @@ zulip_botserver/zulip_botserver/server.py
4244
zulip_botserver/setup.py
4345
""".split()
4446

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

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

8590
extra_args = ["--check-untyped-defs",
@@ -98,8 +103,14 @@ if args.quick:
98103
extra_args.append("--quick")
99104

100105
# 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.")
106+
status = 0
107+
for repo, python_files in repo_python_files.items():
108+
print("Running mypy for `{}`.".format(repo))
109+
if python_files:
110+
print(python_files)
111+
result = subprocess.call([mypy_command] + extra_args + python_files)
112+
if result != 0:
113+
status = result
114+
else:
115+
print("There are no files to run mypy on.")
116+
sys.exit(status)

0 commit comments

Comments
 (0)