2016-04-07 07:22:04 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
import os
|
2016-04-27 09:28:20 +02:00
|
|
|
from os.path import dirname, abspath
|
2016-04-07 07:22:04 +02:00
|
|
|
import sys
|
|
|
|
import lister
|
|
|
|
import argparse
|
|
|
|
import subprocess
|
2016-04-27 09:28:20 +02:00
|
|
|
import six
|
2016-04-07 07:22:04 +02:00
|
|
|
|
|
|
|
exclude="""
|
|
|
|
api/integrations/
|
|
|
|
api/zulip/__init__.py
|
|
|
|
bots/jabber_mirror_backend.py
|
|
|
|
bots/zephyr_mirror_backend.py
|
|
|
|
docs/conf.py
|
|
|
|
puppet/zulip_internal/files/postgresql/pg_backup_and_purge.py
|
|
|
|
tools/deprecated/
|
|
|
|
zproject/
|
|
|
|
zerver/lib/actions.py
|
|
|
|
zerver/lib/bugdown/fenced_code.py
|
|
|
|
zerver/lib/statistics.py
|
|
|
|
zerver/migrations/
|
|
|
|
zerver/tests/
|
2016-05-05 21:48:41 +02:00
|
|
|
zerver/views/webhooks/jira.py
|
2016-04-07 07:22:04 +02:00
|
|
|
zilencer/models.py
|
|
|
|
""".split()
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description="Run mypy on files tracked by git.")
|
|
|
|
parser.add_argument('targets', nargs='*', default=[],
|
|
|
|
help="""files and directories to include in the result.
|
|
|
|
If this is not specified, the current directory is used""")
|
|
|
|
parser.add_argument('-m', '--modified', action='store_true', default=False, help='list only modified files')
|
|
|
|
parser.add_argument('-a', '--all', dest='all', action='store_true', default=False,
|
|
|
|
help="""run mypy on all python files, ignoring the exclude list.
|
|
|
|
This is useful if you have to find out which files fail mypy check.""")
|
|
|
|
args = parser.parse_args()
|
|
|
|
if args.all:
|
|
|
|
exclude = []
|
|
|
|
|
|
|
|
python_files = lister.list_files(targets=args.targets, ftypes=['py'], use_shebang=False,
|
|
|
|
modified_only=args.modified, exclude=exclude)
|
|
|
|
|
2016-04-27 09:28:20 +02:00
|
|
|
# Use zulip-py3-venv's mypy if it's available and we're on python 2
|
|
|
|
PY3_VENV_DIR = "/srv/zulip-py3-venv"
|
|
|
|
MYPY_VENV_PATH = os.path.join(PY3_VENV_DIR, "bin", "mypy")
|
|
|
|
if six.PY2 and os.path.exists(MYPY_VENV_PATH):
|
|
|
|
mypy_command = MYPY_VENV_PATH
|
|
|
|
print("Using mypy from", mypy_command)
|
|
|
|
else:
|
|
|
|
mypy_command = "mypy"
|
|
|
|
|
2016-04-07 07:22:04 +02:00
|
|
|
if python_files:
|
2016-05-05 21:48:41 +02:00
|
|
|
rc = subprocess.call([mypy_command, "--silent-imports", "--py2", "--check-untyped-defs"] + python_files)
|
2016-04-07 07:22:04 +02:00
|
|
|
if not rc:
|
|
|
|
print("The mypy static type checker for python detected no errors!")
|
|
|
|
else:
|
|
|
|
print("\nThe mypy static type checker for Python threw some errors,")
|
|
|
|
print("which indicates a bug in your code or incorrect type annotations.")
|
2016-04-28 21:35:54 +02:00
|
|
|
print("Please see http://zulip.readthedocs.io/en/latest/mypy.html for details")
|
|
|
|
print("on mypy, how Zulip is using mypy, and how to debug common issues.")
|
2016-04-07 07:22:04 +02:00
|
|
|
sys.exit(rc)
|
|
|
|
else:
|
|
|
|
print("There are no files to run mypy on.")
|