Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate mypy in Travis CI #639

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ env:
- TEST_SUITE=backend
- TEST_SUITE=production
- TEST_SUITE=py3k
- TEST_SUITE=mypy
language: python
python:
- "2.7"
Expand Down
9 changes: 7 additions & 2 deletions tools/lister.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_ftype(fpath, use_shebang):
return ''

def list_files(targets=[], ftypes=[], use_shebang=True, modified_only=False,
exclude=[], group_by_ftype=False):
exclude=[], group_by_ftype=False, exclude_patterns=[]):
"""
List files tracked by git.
Returns a list of files which are either in targets or in directories in targets.
Expand Down Expand Up @@ -72,6 +72,9 @@ def list_files(targets=[], ftypes=[], use_shebang=True, modified_only=False,
expath = expath.rstrip('/')
if fpath == expath or fpath.startswith(expath + '/'):
in_exclude = True
for expattern in exclude_patterns:
if expattern in fpath:
in_exclude = True
if in_exclude:
continue

Expand Down Expand Up @@ -103,11 +106,13 @@ def list_files(targets=[], ftypes=[], use_shebang=True, modified_only=False,
help="list of file types to filter on. All files are included if this option is absent")
parser.add_argument('--ext-only', dest='extonly', action='store_true', default=False, help='only use extension to determine file type')
parser.add_argument('--exclude', nargs='+', help='list of files and directories to exclude from listing')
parser.add_argument('--exclude_patterns', nargs='+', help='excludes all the files which includes patterns in exclude list')
args = parser.parse_args()
args.targets = args.targets or []
args.ftypes = args.ftypes or []
args.exclude = args.exclude or []
args.exclude_patterns = args.exclude_patterns or []
listing = list_files(targets=args.targets, ftypes=args.ftypes, use_shebang=not args.extonly,
modified_only=args.modified, exclude=args.exclude)
modified_only=args.modified, exclude=args.exclude, exclude_patterns=args.exclude_patterns)
for l in listing:
print(l)
49 changes: 49 additions & 0 deletions tools/run-mypy
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python2.7
from __future__ import print_function
from __future__ import absolute_import
import os
import re
import sys
import optparse
import subprocess
import traceback

import lister


targets = """
zproject
bots
zilencer
analytics
corporate
confirmation
tools
scripts/setup
scripts/lib
*.py
api
""".split()


# exclude commands
exclude_patterns = """
test
fenced_code
settings
""".split()

by_lang = lister.list_files(targets=targets, modified_only=False, use_shebang=True,
ftypes=['py'], group_by_ftype=True, exclude_patterns=exclude_patterns)

# mypy command to run silently
result = subprocess.Popen(["mypy", "--silent", "--py2", "--check-untyped-defs"] + by_lang['py'],
stdout = subprocess.PIPE,
stderr = subprocess.PIPE)

failed = False
for pipe in (result.stdout, result.stderr):
for ln in pipe:
sys.stdout.write(ln)
failed = True
sys.exit(1 if failed else 0)
5 changes: 5 additions & 0 deletions tools/travis/mypy
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -e
set -x

./tools/run-mypy
5 changes: 5 additions & 0 deletions tools/travis/setup-mypy
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -e
set -x
sudo apt-get install python3 python3-pip -y
sudo pip3 install git+git://github.com/python/mypy.git