|
19 | 19 |
|
20 | 20 | SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )" |
21 | 21 | SPARK_ROOT_DIR="$(dirname "$SCRIPT_DIR")" |
22 | | -PEP8_REPORT_PATH="$SPARK_ROOT_DIR/dev/pep8-report.txt" |
| 22 | +PATHS_TO_CHECK="./python/pyspark/ ./ec2/spark_ec2.py ./examples/src/main/python/" |
| 23 | +PYTHON_LINT_REPORT_PATH="$SPARK_ROOT_DIR/dev/python-lint-report.txt" |
23 | 24 |
|
24 | 25 | cd "$SPARK_ROOT_DIR" |
25 | 26 |
|
| 27 | +# compileall: https://docs.python.org/2/library/compileall.html |
| 28 | +python -B -m compileall -q -l $PATHS_TO_CHECK > "$PYTHON_LINT_REPORT_PATH" |
| 29 | +compile_status="${PIPESTATUS[0]}" |
| 30 | + |
26 | 31 | # Get pep8 at runtime so that we don't rely on it being installed on the build server. |
27 | 32 | #+ See: https://github.com/apache/spark/pull/1744#issuecomment-50982162 |
28 | 33 | #+ TODOs: |
29 | | -#+ - Dynamically determine latest release version of pep8 and use that. |
30 | | -#+ - Download this from a more reliable source. (GitHub raw can be flaky, apparently. (?)) |
| 34 | +#+ - Download pep8 from PyPI. It's more "official". |
31 | 35 | PEP8_SCRIPT_PATH="$SPARK_ROOT_DIR/dev/pep8.py" |
32 | | -PEP8_SCRIPT_REMOTE_PATH="https://raw.githubusercontent.com/jcrocholl/pep8/1.5.7/pep8.py" |
33 | | -PEP8_PATHS_TO_CHECK="./python/pyspark/ ./ec2/spark_ec2.py ./examples/src/main/python/" |
| 36 | +PEP8_SCRIPT_REMOTE_PATH="https://raw.githubusercontent.com/jcrocholl/pep8/1.6.2/pep8.py" |
34 | 37 |
|
| 38 | +# if [ ! -e "$PEP8_SCRIPT_PATH" ]; then |
35 | 39 | curl --silent -o "$PEP8_SCRIPT_PATH" "$PEP8_SCRIPT_REMOTE_PATH" |
36 | | -curl_status=$? |
| 40 | +curl_status="$?" |
37 | 41 |
|
38 | | -if [ $curl_status -ne 0 ]; then |
| 42 | +if [ "$curl_status" -ne 0 ]; then |
39 | 43 | echo "Failed to download pep8.py from \"$PEP8_SCRIPT_REMOTE_PATH\"." |
40 | | - exit $curl_status |
| 44 | + exit "$curl_status" |
41 | 45 | fi |
42 | | - |
| 46 | +# fi |
43 | 47 |
|
44 | 48 | # There is no need to write this output to a file |
45 | 49 | #+ first, but we do so so that the check status can |
46 | 50 | #+ be output before the report, like with the |
47 | 51 | #+ scalastyle and RAT checks. |
48 | | -python "$PEP8_SCRIPT_PATH" $PEP8_PATHS_TO_CHECK > "$PEP8_REPORT_PATH" |
49 | | -pep8_status=${PIPESTATUS[0]} #$? |
| 52 | +python "$PEP8_SCRIPT_PATH" --ignore=E402,E731,E241,W503,E226 $PATHS_TO_CHECK >> "$PYTHON_LINT_REPORT_PATH" |
| 53 | +pep8_status="${PIPESTATUS[0]}" |
| 54 | + |
| 55 | +if [ "$compile_status" -eq 0 -a "$pep8_status" -eq 0 ]; then |
| 56 | + lint_status=0 |
| 57 | +else |
| 58 | + lint_status=1 |
| 59 | +fi |
50 | 60 |
|
51 | | -if [ $pep8_status -ne 0 ]; then |
52 | | - echo "PEP 8 checks failed." |
53 | | - cat "$PEP8_REPORT_PATH" |
| 61 | +if [ "$lint_status" -ne 0 ]; then |
| 62 | + echo "Python lint checks failed." |
| 63 | + cat "$PYTHON_LINT_REPORT_PATH" |
54 | 64 | else |
55 | | - echo "PEP 8 checks passed." |
| 65 | + echo "Python lint checks passed." |
56 | 66 | fi |
57 | 67 |
|
58 | | -rm "$PEP8_REPORT_PATH" |
59 | 68 | rm "$PEP8_SCRIPT_PATH" |
| 69 | +rm "$PYTHON_LINT_REPORT_PATH" |
60 | 70 |
|
61 | | -exit $pep8_status |
| 71 | +exit "$lint_status" |
0 commit comments