Skip to content

Commit 22a46ca

Browse files
cclaussholdenk
authored andcommitted
[SPARK-25270] lint-python: Add flake8 to find syntax errors and undefined names
## What changes were proposed in this pull request? 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 ## How was this patch tested? $ __flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics__ $ __flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics__ Please review http://spark.apache.org/contributing.html before opening a pull request. Closes #22266 from cclauss/patch-3. Authored-by: cclauss <cclauss@bluewin.ch> Signed-off-by: Holden Karau <holden@pigscanfly.ca>
1 parent 473f2fb commit 22a46ca

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

dev/lint-python

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,23 @@ else
8282
rm "$PYCODESTYLE_REPORT_PATH"
8383
fi
8484

85+
# stop the build if there are Python syntax errors or undefined names
86+
flake8 . --count --select=E901,E999,F821,F822,F823 --max-line-length=100 --show-source --statistics
87+
flake8_status="${PIPESTATUS[0]}"
88+
89+
if [ "$flake8_status" -eq 0 ]; then
90+
lint_status=0
91+
else
92+
lint_status=1
93+
fi
94+
95+
if [ "$lint_status" -ne 0 ]; then
96+
echo "flake8 checks failed."
97+
exit "$lint_status"
98+
else
99+
echo "flake8 checks passed."
100+
fi
101+
85102
# Check that the documentation builds acceptably, skip check if sphinx is not installed.
86103
if hash "$SPHINXBUILD" 2> /dev/null; then
87104
cd python/docs

dev/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
flake8==3.5.0
12
jira==1.0.3
23
PyGithub==1.26.0
34
Unidecode==0.04.19

0 commit comments

Comments
 (0)