tools: Add type annotations.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-10-25 16:23:54 -07:00
parent a9e3fe9d0c
commit 01d5106e9a
2 changed files with 12 additions and 19 deletions

View file

@ -16,7 +16,7 @@ end_format = "\033[0m"
bold = "\033[1m" bold = "\033[1m"
def main(): def main() -> None:
usage = """./tools/provision usage = """./tools/provision
Creates a Python virtualenv. Its Python version is equal to Creates a Python virtualenv. Its Python version is equal to
@ -94,7 +94,7 @@ the Python version this command is executed with."""
# In order to install all required packages for the venv, `pip` needs to be executed by # In order to install all required packages for the venv, `pip` needs to be executed by
# the venv's Python interpreter. `--prefix venv_dir` ensures that all modules are installed # the venv's Python interpreter. `--prefix venv_dir` ensures that all modules are installed
# in the right place. # in the right place.
def install_dependencies(requirements_filename): def install_dependencies(requirements_filename: str) -> None:
pip_path = os.path.join(venv_dir, venv_exec_dir, "pip") pip_path = os.path.join(venv_dir, venv_exec_dir, "pip")
# We first install a modern version of pip that supports --prefix # We first install a modern version of pip that supports --prefix
subprocess.call([pip_path, "install", "pip>=10"]) subprocess.call([pip_path, "install", "pip>=10"])

View file

@ -4,9 +4,8 @@ import argparse
import os import os
import subprocess import subprocess
import sys import sys
from collections import OrderedDict
from pathlib import PurePath from pathlib import PurePath
from typing import Dict, List, cast from typing import List, OrderedDict
from zulint import lister from zulint import lister
@ -25,7 +24,6 @@ exclude = [
# Excluded out of laziness: # Excluded out of laziness:
"zulip_bots/zulip_bots/simple_lib.py", "zulip_bots/zulip_bots/simple_lib.py",
"zulip_bots/zulip_bots/tests/test_lib.py", "zulip_bots/zulip_bots/tests/test_lib.py",
"tools",
] ]
# These files will be included even if excluded by a rule above. # These files will be included even if excluded by a rule above.
@ -93,8 +91,6 @@ force_include = [
"zulip_bots/zulip_bots/bots/susi/test_susi.py", "zulip_bots/zulip_bots/bots/susi/test_susi.py",
"zulip_bots/zulip_bots/bots/front/front.py", "zulip_bots/zulip_bots/bots/front/front.py",
"zulip_bots/zulip_bots/bots/front/test_front.py", "zulip_bots/zulip_bots/bots/front/test_front.py",
"tools/custom_check.py",
"tools/deploy",
] ]
parser = argparse.ArgumentParser(description="Run mypy on files tracked by git.") parser = argparse.ArgumentParser(description="Run mypy on files tracked by git.")
@ -154,17 +150,14 @@ if args.all:
exclude = [] exclude = []
# find all non-excluded files in current directory # find all non-excluded files in current directory
files_dict = cast( files_dict = lister.list_files(
Dict[str, List[str]], targets=args.targets,
lister.list_files( ftypes=["py", "pyi"],
targets=args.targets, use_shebang=True,
ftypes=["py", "pyi"], modified_only=args.modified,
use_shebang=True, exclude=exclude + ["stubs"],
modified_only=args.modified, group_by_ftype=True,
exclude=exclude + ["stubs"], extless_only=args.scripts_only,
group_by_ftype=True,
extless_only=args.scripts_only,
),
) )
for inpath in force_include: for inpath in force_include:
@ -179,7 +172,7 @@ python_files = [
fpath for fpath in files_dict["py"] if not fpath.endswith(".py") or fpath + "i" not in pyi_files fpath for fpath in files_dict["py"] if not fpath.endswith(".py") or fpath + "i" not in pyi_files
] ]
repo_python_files = OrderedDict( repo_python_files = OrderedDict[str, List[str]](
[("zulip", []), ("zulip_bots", []), ("zulip_botserver", []), ("tools", [])] [("zulip", []), ("zulip_bots", []), ("zulip_botserver", []), ("tools", [])]
) )
for file_path in python_files: for file_path in python_files: