Skip to content

Commit 20bb10f

Browse files
MechCoderdavies
authored andcommitted
[SPARK-8706] [PYSPARK] [PROJECT INFRA] Add pylint checks to PySpark
This adds Pylint checks to PySpark. For now this lazy installs using easy_install to /dev/pylint (similar to the pep8 script). We still need to figure out what rules to be allowed. Author: MechCoder <[email protected]> Closes #7241 from MechCoder/pylint and squashes the following commits: 2fc7291 [MechCoder] Remove pylint test fail 6d883a2 [MechCoder] Silence warnings and make pylint tests fail to check if it works in jenkins f3a5e17 [MechCoder] undefined-variable ca8b749 [MechCoder] Minor changes 71629f8 [MechCoder] remove trailing whitespace 8498ff9 [MechCoder] Remove blacklisted arguments and pointless statements check 1dbd094 [MechCoder] Disable all checks for now 8b8aa8a [MechCoder] Add pylint configuration file 7871bb1 [MechCoder] [SPARK-8706] [PySpark] [Project infra] Add pylint checks to PySpark
1 parent adb33d3 commit 20bb10f

File tree

4 files changed

+457
-11
lines changed

4 files changed

+457
-11
lines changed

dev/lint-python

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
2121
SPARK_ROOT_DIR="$(dirname "$SCRIPT_DIR")"
2222
PATHS_TO_CHECK="./python/pyspark/ ./ec2/spark_ec2.py ./examples/src/main/python/ ./dev/sparktestsupport"
2323
PATHS_TO_CHECK="$PATHS_TO_CHECK ./dev/run-tests.py ./python/run-tests.py"
24-
PYTHON_LINT_REPORT_PATH="$SPARK_ROOT_DIR/dev/python-lint-report.txt"
24+
PEP8_REPORT_PATH="$SPARK_ROOT_DIR/dev/pep8-report.txt"
25+
PYLINT_REPORT_PATH="$SPARK_ROOT_DIR/dev/pylint-report.txt"
26+
PYLINT_INSTALL_INFO="$SPARK_ROOT_DIR/dev/pylint-info.txt"
2527

2628
cd "$SPARK_ROOT_DIR"
2729

2830
# compileall: https://docs.python.org/2/library/compileall.html
29-
python -B -m compileall -q -l $PATHS_TO_CHECK > "$PYTHON_LINT_REPORT_PATH"
31+
python -B -m compileall -q -l $PATHS_TO_CHECK > "$PEP8_REPORT_PATH"
3032
compile_status="${PIPESTATUS[0]}"
3133

3234
# Get pep8 at runtime so that we don't rely on it being installed on the build server.
@@ -47,11 +49,36 @@ if [ ! -e "$PEP8_SCRIPT_PATH" ]; then
4749
fi
4850
fi
4951

52+
# Easy install pylint in /dev/pylint. To easy_install into a directory, the PYTHONPATH should
53+
# be set to the directory.
54+
# dev/pylint should be appended to the PATH variable as well.
55+
# Jenkins by default installs the pylint3 version, so for now this just checks the code quality
56+
# of python3.
57+
export "PYTHONPATH=$SPARK_ROOT_DIR/dev/pylint"
58+
export "PYLINT_HOME=$PYTHONPATH"
59+
export "PATH=$PYTHONPATH:$PATH"
60+
61+
if [ ! -d "$PYLINT_HOME" ]; then
62+
mkdir "$PYLINT_HOME"
63+
# Redirect the annoying pylint installation output.
64+
easy_install -d "$PYLINT_HOME" pylint==1.4.4 &>> "$PYLINT_INSTALL_INFO"
65+
easy_install_status="$?"
66+
67+
if [ "$easy_install_status" -ne 0 ]; then
68+
echo "Unable to install pylint locally in \"$PYTHONPATH\"."
69+
cat "$PYLINT_INSTALL_INFO"
70+
exit "$easy_install_status"
71+
fi
72+
73+
rm "$PYLINT_INSTALL_INFO"
74+
75+
fi
76+
5077
# There is no need to write this output to a file
5178
#+ first, but we do so so that the check status can
5279
#+ be output before the report, like with the
5380
#+ scalastyle and RAT checks.
54-
python "$PEP8_SCRIPT_PATH" --ignore=E402,E731,E241,W503,E226 $PATHS_TO_CHECK >> "$PYTHON_LINT_REPORT_PATH"
81+
python "$PEP8_SCRIPT_PATH" --ignore=E402,E731,E241,W503,E226 $PATHS_TO_CHECK >> "$PEP8_REPORT_PATH"
5582
pep8_status="${PIPESTATUS[0]}"
5683

5784
if [ "$compile_status" -eq 0 -a "$pep8_status" -eq 0 ]; then
@@ -61,13 +88,27 @@ else
6188
fi
6289

6390
if [ "$lint_status" -ne 0 ]; then
64-
echo "Python lint checks failed."
65-
cat "$PYTHON_LINT_REPORT_PATH"
91+
echo "PEP8 checks failed."
92+
cat "$PEP8_REPORT_PATH"
93+
else
94+
echo "PEP8 checks passed."
95+
fi
96+
97+
rm "$PEP8_REPORT_PATH"
98+
99+
for to_be_checked in "$PATHS_TO_CHECK"
100+
do
101+
pylint --rcfile="$SPARK_ROOT_DIR/pylintrc" $to_be_checked >> "$PYLINT_REPORT_PATH"
102+
done
103+
104+
if [ "${PIPESTATUS[0]}" -ne 0 ]; then
105+
lint_status=1
106+
echo "Pylint checks failed."
107+
cat "$PYLINT_REPORT_PATH"
66108
else
67-
echo "Python lint checks passed."
109+
echo "Pylint checks passed."
68110
fi
69111

70-
# rm "$PEP8_SCRIPT_PATH"
71-
rm "$PYTHON_LINT_REPORT_PATH"
112+
rm "$PYLINT_REPORT_PATH"
72113

73114
exit "$lint_status"

0 commit comments

Comments
 (0)