2014-08-06 15:58:24 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
#
|
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
|
|
# this work for additional information regarding copyright ownership.
|
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
# (the "License"); you may not use this file except in compliance with
|
|
|
|
# the License. You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
|
|
|
|
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
|
2014-09-08 13:24:15 -04:00
|
|
|
SPARK_ROOT_DIR="$(dirname "$SCRIPT_DIR")"
|
2015-03-19 15:46:10 -04:00
|
|
|
PATHS_TO_CHECK="./python/pyspark/ ./ec2/spark_ec2.py ./examples/src/main/python/"
|
|
|
|
PYTHON_LINT_REPORT_PATH="$SPARK_ROOT_DIR/dev/python-lint-report.txt"
|
2014-08-06 15:58:24 -04:00
|
|
|
|
2014-09-08 13:24:15 -04:00
|
|
|
cd "$SPARK_ROOT_DIR"
|
2014-08-06 15:58:24 -04:00
|
|
|
|
2015-03-19 15:46:10 -04:00
|
|
|
# compileall: https://docs.python.org/2/library/compileall.html
|
|
|
|
python -B -m compileall -q -l $PATHS_TO_CHECK > "$PYTHON_LINT_REPORT_PATH"
|
|
|
|
compile_status="${PIPESTATUS[0]}"
|
|
|
|
|
2014-08-06 15:58:24 -04:00
|
|
|
# Get pep8 at runtime so that we don't rely on it being installed on the build server.
|
|
|
|
#+ See: https://github.com/apache/spark/pull/1744#issuecomment-50982162
|
|
|
|
#+ TODOs:
|
2015-03-19 15:46:10 -04:00
|
|
|
#+ - Download pep8 from PyPI. It's more "official".
|
2015-04-18 19:46:28 -04:00
|
|
|
PEP8_VERSION="1.6.2"
|
|
|
|
PEP8_SCRIPT_PATH="$SPARK_ROOT_DIR/dev/pep8-$PEP8_VERSION.py"
|
|
|
|
PEP8_SCRIPT_REMOTE_PATH="https://raw.githubusercontent.com/jcrocholl/pep8/$PEP8_VERSION/pep8.py"
|
2014-08-06 15:58:24 -04:00
|
|
|
|
2015-04-18 19:46:28 -04:00
|
|
|
if [ ! -e "$PEP8_SCRIPT_PATH" ]; then
|
|
|
|
curl --silent -o "$PEP8_SCRIPT_PATH" "$PEP8_SCRIPT_REMOTE_PATH"
|
|
|
|
curl_status="$?"
|
2014-08-06 15:58:24 -04:00
|
|
|
|
2015-04-18 19:46:28 -04:00
|
|
|
if [ "$curl_status" -ne 0 ]; then
|
|
|
|
echo "Failed to download pep8.py from \"$PEP8_SCRIPT_REMOTE_PATH\"."
|
|
|
|
exit "$curl_status"
|
|
|
|
fi
|
2014-08-06 15:58:24 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# There is no need to write this output to a file
|
|
|
|
#+ first, but we do so so that the check status can
|
|
|
|
#+ be output before the report, like with the
|
|
|
|
#+ scalastyle and RAT checks.
|
2015-03-19 15:46:10 -04:00
|
|
|
python "$PEP8_SCRIPT_PATH" --ignore=E402,E731,E241,W503,E226 $PATHS_TO_CHECK >> "$PYTHON_LINT_REPORT_PATH"
|
|
|
|
pep8_status="${PIPESTATUS[0]}"
|
|
|
|
|
|
|
|
if [ "$compile_status" -eq 0 -a "$pep8_status" -eq 0 ]; then
|
|
|
|
lint_status=0
|
|
|
|
else
|
|
|
|
lint_status=1
|
|
|
|
fi
|
2014-08-06 15:58:24 -04:00
|
|
|
|
2015-03-19 15:46:10 -04:00
|
|
|
if [ "$lint_status" -ne 0 ]; then
|
|
|
|
echo "Python lint checks failed."
|
|
|
|
cat "$PYTHON_LINT_REPORT_PATH"
|
2014-08-06 15:58:24 -04:00
|
|
|
else
|
2015-03-19 15:46:10 -04:00
|
|
|
echo "Python lint checks passed."
|
2014-08-06 15:58:24 -04:00
|
|
|
fi
|
|
|
|
|
2015-04-18 19:46:28 -04:00
|
|
|
# rm "$PEP8_SCRIPT_PATH"
|
2015-03-19 15:46:10 -04:00
|
|
|
rm "$PYTHON_LINT_REPORT_PATH"
|
2014-08-06 15:58:24 -04:00
|
|
|
|
2015-03-19 15:46:10 -04:00
|
|
|
exit "$lint_status"
|