diff --git a/tensorflow/tools/ci_build/ci_sanity.sh b/tensorflow/tools/ci_build/ci_sanity.sh index 2285677fe16..1979e29f2a3 100755 --- a/tensorflow/tools/ci_build/ci_sanity.sh +++ b/tensorflow/tools/ci_build/ci_sanity.sh @@ -13,6 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== +# +# Usage: ci_sanity.sh [options] +# +# Options: +# run sanity checks: python 2&3 pylint checks and bazel nobuild +# --pep8 run pep8 test only # Current script directory SCRIPT_DIR=$( cd ${0%/*} && pwd -P ) @@ -126,6 +132,48 @@ do_pylint() { fi } +# Run pep8 check +do_pep8() { + # Usage: do_pep8 + + PEP8_BIN="/usr/local/bin/pep8" + PYTHON_SRC_FILES=$(find tensorflow -name '*.py') + PEP8_CONFIG_FILE="${SCRIPT_DIR}/pep8" + + if [[ ! -f "${PEP8_CONFIG_FILE}" ]]; then + die "ERROR: Cannot find pep8 config file at ${PEP8_CONFIG_FILE}" + fi + echo "See \"${PEP8_CONFIG_FILE}\" for pep8 config( e.g., ignored errors)" + + NUM_SRC_FILES=$(echo ${PYTHON_SRC_FILES} | wc -w) + + echo "Running pep8 on ${NUM_SRC_FILES} files" + echo "" + + PEP8_START_TIME=$(date +'%s') + PEP8_OUTPUT_FILE="$(mktemp)_pep8_output.log" + + rm -rf ${PEP8_OUTPUT_FILE} + + ${PEP8_BIN} --config="${PEP8_CONFIG_FILE}" --statistics \ + ${PYTHON_SRC_FILES} 2>&1 | tee ${PEP8_OUTPUT_FILE} + PEP8_END_TIME=$(date +'%s') + + echo "" + echo "pep8 took $((${PEP8_END_TIME} - ${PEP8_START_TIME})) s" + echo "" + + if [[ -s ${PEP8_OUTPUT_FILE} ]]; then + echo "FAIL: pep8 found above errors and/or warnings." + return 1 + else + echo "PASS: No pep8 errors or warnings were found" + return 0 + fi +} + + + # Run bazel build --nobuild to test the validity of the BUILD files do_bazel_nobuild() { BUILD_TARGET="//tensorflow/..." @@ -149,6 +197,12 @@ do_bazel_nobuild() { SANITY_STEPS=("do_pylint PYTHON2" "do_pylint PYTHON3" "do_bazel_nobuild") SANITY_STEPS_DESC=("Python 2 pylint" "Python 3 pylint" "bazel nobuild") +# Only run pep8 test if "--pep8" option supplied +if [[ "$1" == "--pep8" ]]; then + SANITY_STEPS=("do_pep8") + SANITY_STEPS_DESC=("pep8 test") +fi + FAIL_COUNTER=0 PASS_COUNTER=0 STEP_EXIT_CODES=() diff --git a/tensorflow/tools/ci_build/install/install_pip_packages.sh b/tensorflow/tools/ci_build/install/install_pip_packages.sh index d244a249504..9f07fabdaf6 100755 --- a/tensorflow/tools/ci_build/install/install_pip_packages.sh +++ b/tensorflow/tools/ci_build/install/install_pip_packages.sh @@ -79,3 +79,8 @@ pip3 install py-cpuinfo # pylint tests require the following: pip install pylint pip3 install pylint + +# pep8 tests require the following: +pip install pep8 +pip3 install pep8 + diff --git a/tensorflow/tools/ci_build/pep8 b/tensorflow/tools/ci_build/pep8 new file mode 100644 index 00000000000..754278de49c --- /dev/null +++ b/tensorflow/tools/ci_build/pep8 @@ -0,0 +1,12 @@ +[pep8] + +# Skip errors and warnings +# E111 indentation is not a multiple of four +# E114 indentation is not a multiple of four (comment) +ignore=E114,E111 + +# Set maximum allowed line length (default: 79) +max-line-length=80 + +# Set the error format [default|pylint|] +format=pylint \ No newline at end of file