Skip to content

Commit a8e1c98

Browse files
committed
[SPARK-25962][BUILD][PYTHON] Specify minimum versions for both pydocstyle and flake8 in 'lint-python' script
## What changes were proposed in this pull request? This PR explicitly specifies `flake8` and `pydocstyle` versions. - It checks flake8 binary executable - flake8 version check >= 3.5.0 - pydocstyle >= 3.0.0 (previously it was == 3.0.0) ## How was this patch tested? Manually tested. Closes #22963 from HyukjinKwon/SPARK-25962. Authored-by: hyukjinkwon <[email protected]> Signed-off-by: hyukjinkwon <[email protected]>
1 parent e4561e1 commit a8e1c98

File tree

1 file changed

+41
-17
lines changed

1 file changed

+41
-17
lines changed

dev/lint-python

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ PYCODESTYLE_REPORT_PATH="$SPARK_ROOT_DIR/dev/pycodestyle-report.txt"
2626
PYDOCSTYLE_REPORT_PATH="$SPARK_ROOT_DIR/dev/pydocstyle-report.txt"
2727
PYLINT_REPORT_PATH="$SPARK_ROOT_DIR/dev/pylint-report.txt"
2828
PYLINT_INSTALL_INFO="$SPARK_ROOT_DIR/dev/pylint-info.txt"
29+
2930
PYDOCSTYLEBUILD="pydocstyle"
30-
EXPECTED_PYDOCSTYLEVERSION="3.0.0"
31-
PYDOCSTYLEVERSION=$(python -c 'import pkg_resources; print(pkg_resources.get_distribution("pydocstyle").version)' 2> /dev/null)
31+
MINIMUM_PYDOCSTYLEVERSION="3.0.0"
32+
33+
FLAKE8BUILD="flake8"
34+
MINIMUM_FLAKE8="3.5.0"
35+
3236
SPHINXBUILD=${SPHINXBUILD:=sphinx-build}
3337
SPHINX_REPORT_PATH="$SPARK_ROOT_DIR/dev/sphinx-report.txt"
3438

@@ -87,27 +91,47 @@ else
8791
rm "$PYCODESTYLE_REPORT_PATH"
8892
fi
8993

90-
# stop the build if there are Python syntax errors or undefined names
91-
flake8 . --count --select=E901,E999,F821,F822,F823 --max-line-length=100 --show-source --statistics
92-
flake8_status="${PIPESTATUS[0]}"
94+
# Check by flake8
95+
if hash "$FLAKE8BUILD" 2> /dev/null; then
96+
FLAKE8VERSION="$( $FLAKE8BUILD --version 2> /dev/null )"
97+
VERSION=($FLAKE8VERSION)
98+
IS_EXPECTED_FLAKE8=$(python -c 'from distutils.version import LooseVersion; \
99+
print(LooseVersion("""'${VERSION[0]}'""") >= LooseVersion("""'$MINIMUM_FLAKE8'"""))' 2> /dev/null)
100+
if [[ "$IS_EXPECTED_FLAKE8" == "True" ]]; then
101+
# stop the build if there are Python syntax errors or undefined names
102+
$FLAKE8BUILD . --count --select=E901,E999,F821,F822,F823 --max-line-length=100 --show-source --statistics
103+
flake8_status="${PIPESTATUS[0]}"
104+
105+
if [ "$flake8_status" -eq 0 ]; then
106+
lint_status=0
107+
else
108+
lint_status=1
109+
fi
93110

94-
if [ "$flake8_status" -eq 0 ]; then
95-
lint_status=0
111+
if [ "$lint_status" -ne 0 ]; then
112+
echo "flake8 checks failed."
113+
exit "$lint_status"
114+
else
115+
echo "flake8 checks passed."
116+
fi
117+
else
118+
echo "The flake8 version needs to be "$MINIMUM_FLAKE8" at latest. Your current version is '"$FLAKE8VERSION"'."
119+
echo "flake8 checks failed."
120+
exit 1
121+
fi
96122
else
97-
lint_status=1
98-
fi
99-
100-
if [ "$lint_status" -ne 0 ]; then
123+
echo >&2 "The flake8 command was not found."
101124
echo "flake8 checks failed."
102-
exit "$lint_status"
103-
else
104-
echo "flake8 checks passed."
125+
exit 1
105126
fi
106127

107128
# Check python document style, skip check if pydocstyle is not installed.
108129
if hash "$PYDOCSTYLEBUILD" 2> /dev/null; then
109-
if [[ "$PYDOCSTYLEVERSION" == "$EXPECTED_PYDOCSTYLEVERSION" ]]; then
110-
pydocstyle --config=dev/tox.ini $DOC_PATHS_TO_CHECK >> "$PYDOCSTYLE_REPORT_PATH"
130+
PYDOCSTYLEVERSION="$( $PYDOCSTYLEBUILD --version 2> /dev/null )"
131+
IS_EXPECTED_PYDOCSTYLEVERSION=$(python -c 'from distutils.version import LooseVersion; \
132+
print(LooseVersion("""'$PYDOCSTYLEVERSION'""") >= LooseVersion("""'$MINIMUM_PYDOCSTYLEVERSION'"""))')
133+
if [[ "$IS_EXPECTED_PYDOCSTYLEVERSION" == "True" ]]; then
134+
$PYDOCSTYLEBUILD --config=dev/tox.ini $DOC_PATHS_TO_CHECK >> "$PYDOCSTYLE_REPORT_PATH"
111135
pydocstyle_status="${PIPESTATUS[0]}"
112136

113137
if [ "$compile_status" -eq 0 -a "$pydocstyle_status" -eq 0 ]; then
@@ -121,7 +145,7 @@ if hash "$PYDOCSTYLEBUILD" 2> /dev/null; then
121145
fi
122146

123147
else
124-
echo "The pydocstyle version needs to be latest 3.0.0. Skipping pydoc checks for now"
148+
echo "The pydocstyle version needs to be "$MINIMUM_PYDOCSTYLEVERSION" at latest. Your current version is "$PYDOCSTYLEVERSION". Skipping pydoc checks for now."
125149
fi
126150
else
127151
echo >&2 "The pydocstyle command was not found. Skipping pydoc checks for now"

0 commit comments

Comments
 (0)