From 129119803eacbca1a53384893424e4ae75774626 Mon Sep 17 00:00:00 2001 From: cclauss Date: Wed, 29 Aug 2018 11:46:38 +0200 Subject: [PATCH 1/4] lint-python: Add flake8 tests to find Python syntax errors and undefined names Add [flake8](http://flake8.pycqa.org) tests to find Python syntax errors and undefined names. __E901,E999,F821,F822,F823__ are the "_showstopper_" flake8 issues that can halt the runtime with a SyntaxError, NameError, etc. Most other flake8 issues are merely "style violations" -- useful for readability but they do not effect runtime safety. * F821: undefined name `name` * F822: undefined name `name` in `__all__` * F823: local variable name referenced before assignment * E901: SyntaxError or IndentationError * E999: SyntaxError -- failed to compile a file into an Abstract Syntax Tree --- dev/lint-python | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/dev/lint-python b/dev/lint-python index f738af9c49763..fa837b163da86 100755 --- a/dev/lint-python +++ b/dev/lint-python @@ -82,6 +82,26 @@ else rm "$PYCODESTYLE_REPORT_PATH" fi +python -m pip install flake8 +# stop the build if there are Python syntax errors or undefined names +flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics +flake8_status="${PIPESTATUS[0]}" +# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide +flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + +if [ "$flake8_status" -eq 0 ]; then + lint_status=0 +else + lint_status=1 +fi + +if [ "$lint_status" -ne 0 ]; then + echo "flake8 checks failed." + exit "$lint_status" +else + echo "flake8 checks passed." +fi + # Check that the documentation builds acceptably, skip check if sphinx is not installed. if hash "$SPHINXBUILD" 2> /dev/null; then cd python/docs From c8c05431c451307b2a55edc6ad3ae3f7569e356b Mon Sep 17 00:00:00 2001 From: cclauss Date: Fri, 31 Aug 2018 00:10:23 +0200 Subject: [PATCH 2/4] Remove: python -m pip install flake8 --- dev/lint-python | 1 - 1 file changed, 1 deletion(-) diff --git a/dev/lint-python b/dev/lint-python index fa837b163da86..fdc82ed39dc7d 100755 --- a/dev/lint-python +++ b/dev/lint-python @@ -82,7 +82,6 @@ else rm "$PYCODESTYLE_REPORT_PATH" fi -python -m pip install flake8 # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics flake8_status="${PIPESTATUS[0]}" From b87c49e5e36105e392a81e0547b1002b336e6824 Mon Sep 17 00:00:00 2001 From: cclauss Date: Fri, 31 Aug 2018 19:31:20 +0200 Subject: [PATCH 3/4] --max-line-length=100 and remove second round of tests --- dev/lint-python | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dev/lint-python b/dev/lint-python index fdc82ed39dc7d..a98a251af9e6c 100755 --- a/dev/lint-python +++ b/dev/lint-python @@ -83,10 +83,8 @@ else fi # stop the build if there are Python syntax errors or undefined names -flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics +flake8 . --count --select=E901,E999,F821,F822,F823 --max-line-length=100 --show-source --statistics flake8_status="${PIPESTATUS[0]}" -# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide -flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics if [ "$flake8_status" -eq 0 ]; then lint_status=0 From 786d0c9e730d04885d33da6d2b6cc098ee1dcf1e Mon Sep 17 00:00:00 2001 From: cclauss Date: Fri, 31 Aug 2018 19:33:52 +0200 Subject: [PATCH 4/4] Add flake8==3.5.0 to spark/dev/requirements.txt --- dev/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/requirements.txt b/dev/requirements.txt index fa833ab96b8e7..3fdd3425ffcc2 100644 --- a/dev/requirements.txt +++ b/dev/requirements.txt @@ -1,3 +1,4 @@ +flake8==3.5.0 jira==1.0.3 PyGithub==1.26.0 Unidecode==0.04.19