diff --git a/.flake8 b/.flake8 index a1288dba5..d0c265bc1 100644 --- a/.flake8 +++ b/.flake8 @@ -15,7 +15,11 @@ [flake8] ignore = F401, F811, F821, E127, E128, E301, E302, E305, E501, E701, E704, E999, B303 +# We are checking with Python 3 but many of the stubs are Python 2 stubs. +# A nice future improvement would be to provide separate .flake8 +# configurations for Python 2 and Python 3 files. +builtins = StandardError,apply,basestring,buffer,cmp,coerce,execfile,file,intern,long,raw_input,reduce,reload,unichr,unicode,xrange # Errors that we need to fix before enabling flake8 by default: -# 936 F821 undefined name - FIXME: re-enable and add missing imports +# 208 F821 undefined name - FIXME: re-enable and add missing imports # 6 E999 invalid syntax - FIXME: re-enable after flake8 is running from Python 3.6 diff --git a/.travis.yml b/.travis.yml index 1db0ec621..9e6a51463 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ language: python matrix: include: - python: "3.5" - env: TEST_CMD="./tests/flake8_test.py" + env: TEST_CMD="flake8" - python: "3.5" env: TEST_CMD="./tests/mypy_test.py" - python: "2.7" @@ -12,7 +12,7 @@ matrix: install: # pytype needs py-2.7, mypy needs py-3.2+. Additional logic in runtests.py - - if [[ $TRAVIS_PYTHON_VERSION == '3.5' ]]; then pip install -U git+git://github.com/python/mypy git+git://github.com/dropbox/typed_ast flake8-bugbear; fi + - if [[ $TRAVIS_PYTHON_VERSION == '3.5' ]]; then pip install -U git+git://github.com/python/mypy git+git://github.com/dropbox/typed_ast flake8==3.2.1 flake8-bugbear flake8-pyi; fi - if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pip install -U git+git://github.com/google/pytype; fi script: diff --git a/README.md b/README.md index adc239748..4fbe1a495 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ mypy tests and flake8 tests by invoking: ``` (.venv3)$ python tests/mypy_test.py ... -(.venv3)$ python tests/flake8_test.py +(.venv3)$ flake8 ... ``` To run the pytype tests, you need a separate virtual environment with @@ -146,7 +146,7 @@ running mypy --python-version 3.2 --strict-optional # with 453 files running mypy --python-version 2.7 --strict-optional # with 502 files Running pytype tests... Ran pytype with 244 pyis, got 0 errors. -Running flake8 on 886 .pyi files... +Running flake8... flake8 run clean. (.venv3)$ ``` diff --git a/requirements-tests-py3.txt b/requirements-tests-py3.txt index 28aa0670c..66d4a2077 100644 --- a/requirements-tests-py3.txt +++ b/requirements-tests-py3.txt @@ -1,4 +1,5 @@ mypy-lang>=0.4.6 typed-ast>=0.6.1 -flake8>=3.2.1 +flake8==3.2.1 flake8-bugbear>=16.12.2 +flake8-pyi>=16.12.0 diff --git a/runtests.sh b/runtests.sh index 4646841d2..164506027 100755 --- a/runtests.sh +++ b/runtests.sh @@ -2,4 +2,5 @@ ./tests/mypy_test.py ./tests/pytype_test.py -./tests/flake8_test.py +echo "Running flake8..." +flake8 && echo "flake8 run clean." diff --git a/tests/flake8_test.py b/tests/flake8_test.py deleted file mode 100755 index 2f00328fc..000000000 --- a/tests/flake8_test.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python3 -import pathlib -import subprocess -import sys - -PY2_ONLY_KEYWORDS = [ - 'StandardError', - 'apply', - 'basestring', - 'buffer', - 'cmp', - 'coerce', - 'execfile', - 'file', - 'intern', - 'long', - 'raw_input', - 'reduce', - 'reload', - 'unichr', - 'unicode', - 'xrange', -] - -root = pathlib.Path(__file__).parent.parent -paths = list(sorted(str(p) for p in root.glob('**/*.pyi'))) -window = 0 -size = 100 -returncode = 0 - -print('Running flake8 on {} .pyi files...'.format(len(paths))) - -while True: - chunk = paths[window:window + size] - if not chunk: - break - - proc = subprocess.run( - ['flake8', '--builtins=' + ','.join(PY2_ONLY_KEYWORDS)] + chunk, - ) - if proc.returncode: - print('flake8 run failed!') - sys.exit(1) - - window += size - -print('flake8 run clean.') diff --git a/tests/mypy_test.py b/tests/mypy_test.py index 3498059c4..d474009e4 100755 --- a/tests/mypy_test.py +++ b/tests/mypy_test.py @@ -126,7 +126,7 @@ def main(): flags.append('--strict-optional') if (major, minor) >= (3, 6): flags.append('--fast-parser') - ##flags.append('--warn-unused-ignores') # Fast parser and regular parser disagree. + # flags.append('--warn-unused-ignores') # Fast parser and regular parser disagree. sys.argv = ['mypy'] + flags + files if args.verbose: print("running", ' '.join(sys.argv))