Skip to content

Commit d5573c5

Browse files
rekhajoshmsrowen
authored andcommitted
[SPARK-23367][BUILD] Include python document style checking
## What changes were proposed in this pull request? Includes python document style checking. - Use sphinx like check, run only if pydocstyle installed on machine/jenkins - use pydocstyle rather than single file version pep257.py, which is much older and had some known issues - verify pydocstyle latest 3.0.0 is in use, to ensure latest doc checks are getting executed - ignore (inclusion/exclusion error codes) features and support via tox.ini - Be non-breaking change and allow updating docstyle to standards at easy pace ## How was this patch tested? ./dev/run-tests Closes apache#22425 from rekhajoshm/SPARK-23367-2. Authored-by: Rekha Joshi <[email protected]> Signed-off-by: Sean Owen <[email protected]>
1 parent 6f05669 commit d5573c5

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

dev/lint-python

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
2121
SPARK_ROOT_DIR="$(dirname "$SCRIPT_DIR")"
2222
# Exclude auto-generated configuration file.
2323
PATHS_TO_CHECK="$( cd "$SPARK_ROOT_DIR" && find . -name "*.py" )"
24+
DOC_PATHS_TO_CHECK="$( cd "$SPARK_ROOT_DIR" && find . -name "*.py" | grep -vF 'functions.py' )"
2425
PYCODESTYLE_REPORT_PATH="$SPARK_ROOT_DIR/dev/pycodestyle-report.txt"
26+
PYDOCSTYLE_REPORT_PATH="$SPARK_ROOT_DIR/dev/pydocstyle-report.txt"
2527
PYLINT_REPORT_PATH="$SPARK_ROOT_DIR/dev/pylint-report.txt"
2628
PYLINT_INSTALL_INFO="$SPARK_ROOT_DIR/dev/pylint-info.txt"
29+
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)
2732
SPHINXBUILD=${SPHINXBUILD:=sphinx-build}
2833
SPHINX_REPORT_PATH="$SPARK_ROOT_DIR/dev/sphinx-report.txt"
2934

@@ -99,6 +104,29 @@ else
99104
echo "flake8 checks passed."
100105
fi
101106

107+
# Check python document style, skip check if pydocstyle is not installed.
108+
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"
111+
pydocstyle_status="${PIPESTATUS[0]}"
112+
113+
if [ "$compile_status" -eq 0 -a "$pydocstyle_status" -eq 0 ]; then
114+
echo "pydocstyle checks passed."
115+
rm "$PYDOCSTYLE_REPORT_PATH"
116+
else
117+
echo "pydocstyle checks failed."
118+
cat "$PYDOCSTYLE_REPORT_PATH"
119+
rm "$PYDOCSTYLE_REPORT_PATH"
120+
exit 1
121+
fi
122+
123+
else
124+
echo "The pydocstyle version needs to be latest 3.0.0. Skipping pydoc checks for now"
125+
fi
126+
else
127+
echo >&2 "The pydocstyle command was not found. Skipping pydoc checks for now"
128+
fi
129+
102130
# Check that the documentation builds acceptably, skip check if sphinx is not installed.
103131
if hash "$SPHINXBUILD" 2> /dev/null; then
104132
cd python/docs

dev/tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@
1717
ignore=E226,E241,E305,E402,E722,E731,E741,W503,W504
1818
max-line-length=100
1919
exclude=cloudpickle.py,heapq3.py,shared.py,python/docs/conf.py,work/*/*.py,python/.eggs/*,dist/*
20+
[pydocstyle]
21+
ignore=D100,D101,D102,D103,D104,D105,D106,D107,D200,D201,D202,D203,D204,D205,D206,D207,D208,D209,D210,D211,D212,D213,D214,D215,D300,D301,D302,D400,D401,D402,D403,D404,D405,D406,D407,D408,D409,D410,D411,D412,D413,D414

0 commit comments

Comments
 (0)