run-mypy: Stop running `mypy --py2`.

Also unconditionally use the `mypy` from our virtualenv --
that's how we ensure we use a common version across different
Zulip developers and in CI.

And as a side effect of cutting some Python 2 vs. Python 3 logic,
fix a bug where `--all` was having no effect.
This commit is contained in:
Greg Price 2017-08-08 17:17:30 -07:00 committed by Tim Abbott
parent 6346861ccd
commit b8dcac1b42
2 changed files with 7 additions and 30 deletions

View File

@ -18,16 +18,11 @@ os.chdir(os.path.dirname(TOOLS_DIR))
sys.path.append(os.path.dirname(TOOLS_DIR)) sys.path.append(os.path.dirname(TOOLS_DIR))
from lib.test_script import get_provisioning_status from lib.test_script import get_provisioning_status
exclude_common = """ exclude = """
zproject/settings.py zproject/settings.py
zproject/test_settings.py zproject/test_settings.py
""".split() """.split()
exclude_py2 = [] # type: List[str]
exclude_py3 = """
""".split()
parser = argparse.ArgumentParser(description="Run mypy on files tracked by git.") parser = argparse.ArgumentParser(description="Run mypy on files tracked by git.")
parser.add_argument('targets', nargs='*', default=[], parser.add_argument('targets', nargs='*', default=[],
help="""files and directories to include in the result. help="""files and directories to include in the result.
@ -53,10 +48,6 @@ parser.add_argument('--quick', action='store_true', default=False,
parser.add_argument('--force', default=False, parser.add_argument('--force', default=False,
action="store_true", action="store_true",
help='Run tests despite possible provisioning problems.') help='Run tests despite possible provisioning problems.')
group = parser.add_mutually_exclusive_group()
group.add_argument('--py2', default=False, action='store_true', help="Use Python 2 mode")
group.add_argument('--py3', default=False, action='store_true', help="Use Python 3 mode")
args = parser.parse_args() args = parser.parse_args()
if not args.force: if not args.force:
@ -66,19 +57,8 @@ if not args.force:
print('If you really know what you are doing, use --force to run anyway.') print('If you really know what you are doing, use --force to run anyway.')
sys.exit(1) sys.exit(1)
if args.py2:
py_version = 2
elif args.py3:
py_version = 3
else:
py_version = 2
if args.all: if args.all:
exclude = [] # type: List[str] exclude = []
if py_version == 2:
exclude = exclude_common + exclude_py2
else:
exclude = exclude_common + exclude_py3
# find all non-excluded files in current directory # find all non-excluded files in current directory
files_dict = cast(Dict[str, List[str]], files_dict = cast(Dict[str, List[str]],
@ -90,10 +70,10 @@ pyi_files = set(files_dict['pyi'])
python_files = [fpath for fpath in files_dict['py'] python_files = [fpath for fpath in files_dict['py']
if not fpath.endswith('.py') or fpath + 'i' not in pyi_files] if not fpath.endswith('.py') or fpath + 'i' not in pyi_files]
# Use zulip-py3-venv's mypy if it's available and we're on python 2 # Use zulip-py3-venv's mypy if it's available.
PY3_VENV_DIR = "/srv/zulip-py3-venv" VENV_DIR = "/srv/zulip-py3-venv"
MYPY_VENV_PATH = os.path.join(PY3_VENV_DIR, "bin", "mypy") MYPY_VENV_PATH = os.path.join(VENV_DIR, "bin", "mypy")
if six.PY2 and os.path.exists(MYPY_VENV_PATH): if os.path.exists(MYPY_VENV_PATH):
mypy_command = MYPY_VENV_PATH mypy_command = MYPY_VENV_PATH
print("Using mypy from", mypy_command) print("Using mypy from", mypy_command)
else: else:
@ -103,8 +83,6 @@ extra_args = ["--check-untyped-defs",
"--follow-imports=silent", "--follow-imports=silent",
"--scripts-are-modules", "--scripts-are-modules",
"-i", "--cache-dir=var/mypy-cache"] "-i", "--cache-dir=var/mypy-cache"]
if py_version == 2:
extra_args.append("--py2")
if args.linecoverage_report: if args.linecoverage_report:
extra_args.append("--linecoverage-report") extra_args.append("--linecoverage-report")
extra_args.append("var/linecoverage-report") extra_args.append("var/linecoverage-report")

View File

@ -4,8 +4,7 @@ set -e
set -x set -x
retcode=0 retcode=0
./tools/run-mypy --py2 --linecoverage-report || retcode=1 ./tools/run-mypy --linecoverage-report || retcode=1
./tools/run-mypy --py3 || retcode=1
set +x set +x
if [ "$retcode" == "0" ]; then if [ "$retcode" == "0" ]; then
echo "The mypy static type checker for python detected no errors!" echo "The mypy static type checker for python detected no errors!"