From b79473b858ec7b4f86d3439100bd86d482f61b90 Mon Sep 17 00:00:00 2001 From: Bob Hyman Date: Wed, 6 May 2020 21:23:57 -0400 Subject: [PATCH] Run (pure) flake8 in CI; deprecate config for pytest-flake8 --- .travis.yml | 1 + CHANGELOG.rst | 1 + CONTRIBUTING.rst | 14 ++-- news/flake8_in_CI.rst | 25 ++++++ pyproject.toml | 1 + requirements/tests-35.txt | 1 - requirements/tests.txt | 1 - setup.cfg | 169 +++++++++++++++----------------------- tests/conftest.py | 6 ++ 9 files changed, 107 insertions(+), 112 deletions(-) create mode 100644 news/flake8_in_CI.rst diff --git a/.travis.yml b/.travis.yml index 00ba03254..c818017c7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,4 +50,5 @@ script: doctr deploy --deploy-repo xonsh/xonsh-docs .; else xonsh run-tests.xsh --timeout=10; + flake8 fi diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7d63242fc..8ea8f0136 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -349,6 +349,7 @@ v0.9.11 ``aliases['echocat'] = 'echo "hi" and echo "there"'`` will, when run, return .. code-block:: + hi there diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index acbe0e57d..78328e649 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -110,25 +110,25 @@ is open to interpretation. recommendations from PEP8 are not required here. * All Python code should be compliant with Python 3.5+. At some unforeseen date in the future, Python 2.7 support *may* be supported. -* Tests should be written with pytest using a procedural style. Do not use +* Tests should be written with `pytest `_ using a procedural style. Do not use unittest directly or write tests in an object-oriented style. * Test generators make more dots and the dots must flow! You can easily check for style issues, including some outright bugs such -as mispelled variable names, using pylint. If you're using Anaconda you'll -need to run "conda install pylint" once. You can easily run pylint on +as mispelled variable names, using `flake8 `_. If you're using Anaconda you'll +need to run "conda install flake8" once. You can easily run flake8 on the edited files in your uncommited git change:: - $ git status -s | awk '/\.py$$/ { print $2 }' | xargs pylint + $ git status -s | awk '/\.py$$/ { print $2 }' | xargs flake8 If you want to lint the entire code base run:: - $ pylint $(find tests xonsh -name \*.py | sort) + $ flake8 -We also use ``black`` for formatting the code base (which includes running in +We also use `black `_ for formatting the code base (which includes running in our tests):: - $ black --check --exclude=xonsh/ply/ xonsh/ xontrib/ + $ black --check xonsh/ xontrib/ To add this as a git pre-commit hook:: diff --git a/news/flake8_in_CI.rst b/news/flake8_in_CI.rst new file mode 100644 index 000000000..ff0adb96d --- /dev/null +++ b/news/flake8_in_CI.rst @@ -0,0 +1,25 @@ +**Added:** + +* CI step to run flake8 after pytest. + +**Changed:** + +* + +**Deprecated:** + +* `pytest --flake8`_ now exits with error message to use flake8 instead. + Allows single list of lint exceptions to apply in CI and your IDE. + +**Removed:** + +* pytest-flake8 package from requirements\*.txt + +**Fixed:** + +* Updated development guide to reference flake8 instead of pylint +* Corrected flake8 config for allowed exceptions. + +**Security:** + +* diff --git a/pyproject.toml b/pyproject.toml index 6e531307c..160e0bde4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,6 +25,7 @@ exclude = ''' | \.github | \.vscode | \.pytest_cache + | ply )/ ) ''' diff --git a/requirements/tests-35.txt b/requirements/tests-35.txt index ce506ef14..27f024794 100644 --- a/requirements/tests-35.txt +++ b/requirements/tests-35.txt @@ -1,7 +1,6 @@ py pytest flake8 -pytest-flake8 pytest-cov pytest-timeout prompt-toolkit>=2.0 diff --git a/requirements/tests.txt b/requirements/tests.txt index c5e1ce977..a258b3ad9 100644 --- a/requirements/tests.txt +++ b/requirements/tests.txt @@ -1,7 +1,6 @@ py pytest flake8 -pytest-flake8 pytest-cov pytest-timeout prompt-toolkit>=2.0 diff --git a/setup.cfg b/setup.cfg index b805430c3..3dd784554 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,106 +1,69 @@ -[tool:pytest] -flake8-max-line-length = 180 -flake8-ignore = - *.py E122 - *.py E203 # E203 whitespace before ':' - *.py E402 - *.py W503 # line break before binary operators is a good thing - *.py E731 # it's OK to assign lambda to variable - xonsh/pygments_cache.py ALL - # flake8 gives incorrect unused import errors, F401 - xonsh/ast.py F401 - xonsh/platform.py F401 - xonsh/built_ins.py F821 E721 - xonsh/commands_cache.py F841 - xonsh/history.py F821 - xonsh/jupyter_kernel.py E203 - xonsh/pyghooks.py F821 - xonsh/style_tools.py F821 - xonsh/readline_shell.py F401 - xonsh/timings.py F401 - xonsh/tokenize.py F821 F841 - xonsh/tools.py E731 - xonsh/xonfig.py E731 - xonsh/proc.py E261 E265 - xonsh/ptk/key_bindings.py F841 - xonsh/ptk/shell.py E731 - xontrib/vox.py F821 - __amalgam__.py ALL - # we don't care about sphinx autogenerated files - docs/*.py ALL - # we don't care about ply files? - ply/*.py ALL - # these run VERY slowly and give tons of errors - parser*_table.py ALL - # oh come on - setup.py ALL - - # remove these later - *.py E741 # ambiguous variable name - xonsh/color_tools.py E305 - xonsh/inspectors.py E722 - xonsh/lexer.py E741 - xonsh/platform.py E305 - xonsh/style_tools.py E305 - xonsh/tools.py E305 - xonsh/winutils.py E305 - xonsh/completers/_aliases.py E305 - xonsh/completers/python.py E722 - xonsh/parsers/context_check.py E305 - xonsh/xoreutils/*.py E722 E305 - +# Use of pytest --flake8 is deprecated in favor of flake8 direct. +# Thus the developer's IDE can use the same lint config as CI. +# pytest-flake8 --ignore is an incompatible superset of flake8 --ignore, --per-file-ignores and --exclude +# and we don't want to maintain the same list in 2 formats. [flake8] max-line-length = 180 -# ignore ALL hangs on parser_table.py, need exclude= -# flake8 uses os.fnmatch -- different globbing syntax. -exclude = - __amalgam__.py - # we don't care about sphinx autogenerated files - docs/*.py - # we don't care about ply files? - */ply/*.py - # these run VERY slowly and give tons of errors - parser*_table.py - # oh come on - setup.py -ignore = - E122 - , E203 # E203 whitespace before ':' - , E402 - , W503 # line break before binary operators is a good thing - , E741 # ambiguous variable name - , E731 # it's OK to assign lambda to variable. - -per-file-ignores = - xonsh/pygments_cache.py: ALL - # flake8 gives incorrect unused import errors, F401 - xonsh/ast.py: F401 - xonsh/platform.py: F401 - xonsh/built_ins.py: F821, E721 - xonsh/commands_cache.py: F841 - xonsh/history.py: F821 - xonsh/jupyter_kernel.py: E203 - xonsh/pyghooks.py: F821 - xonsh/style_tools.py: F821 - xonsh/readline_shell.py: F401 - xonsh/timings.py: F401 - xonsh/tokenize.py: F821, F841 - xonsh/tools.py: E731 - xonsh/xonfig.py: E731 - xonsh/proc.py: E261, E265 - xonsh/ptk/key_bindings.py: F841 - xonsh/ptk/shell.py: E731 - xontrib/vox.py: F821 - +exclude = + __amalgam__.py, + tests/, + docs/, + */ply/, + parser*_table.py, + build/, + dist/, + setup.py, + .vscode/, + # remove later + pygments_cache.py +# lint nits that are acceptable in Xonsh project: +ignore = + E122, + # E203 whitespace before ':' + E203, + E402, + # line break before binary operators is a good thing + W503, + # accept lambda assigned to a variable + E731, # remove these later - xonsh/color_tools.py: E305 - xonsh/inspectors.py: E722 - xonsh/lexer.py: E741 - xonsh/platform.py: E305 - xonsh/style_tools.py: E305 - xonsh/tools.py: E305 - xonsh/winutils.py: E305 - xonsh/completers/_aliases.py: E305 - xonsh/completers/python.py: E722 - xonsh/parsers/context_check.py: E305 - xonsh/xoreutils/*.py: E722, E305 + # E741 - ambiguous variable name + E741, +# also acceptable in Xonsh project: reference to global names defined at runtime by black magic +builtins = + __xonsh__, + events, + aliases, + XonshError, +per-file-ignores = + # flake8 gives incorrect unused import errors, F401 + tests/tools.py:E128, + xonsh/ast.py:F401, + xonsh/built_ins.py:F821 E721, + xonsh/built_ins.py:E721, + xonsh/commands_cache.py:F841, + xonsh/history.py:F821, + xonsh/jupyter_kernel.py:E203, + xonsh/platform.py:F401 E305, + xonsh/proc.py:E261 E265, + xonsh/ptk/key_bindings.py:F841, + xonsh/ptk/shell.py:E731, + xonsh/pyghooks.py:F821, + xonsh/readline_shell.py:F401, + xonsh/style_tools.py:F821 E305, + xonsh/timings.py:F401, + xonsh/tokenize.py:F821 F841, + xonsh/tools.py:E731 E305, + xonsh/xonfig.py:E731, + xontrib/vox.py:F821, + # remove these later + xonsh/color_tools.py:E305 + xonsh/completers/_aliases.py:E305, + xonsh/completers/python.py:E722, + xonsh/inspectors.py:E722 + xonsh/lexer.py:E741, + xonsh/parsers/context_check.py:E305, + xonsh/style_tools.py:E305, + xonsh/tools.py:E305, + xonsh/winutils.py:E305, + xonsh/xoreutils/*.py:E722 E305, diff --git a/tests/conftest.py b/tests/conftest.py index 772544a99..4c1c854c8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -156,3 +156,9 @@ def xonsh_builtins(monkeypatch, xonsh_events): if hasattr(builtins, attr): delattr(builtins, attr) tasks.clear() # must to this to enable resetting all_jobs + + +def pytest_configure(config): + """Abort test run if --flake8 requested, since it would hang on parser_test.py""" + if config.getoption('--flake8', ''): + pytest.exit("pytest-flake8 no longer supported, use flake8 instead.")