diff options
Diffstat (limited to 'tensorflow/tools/ci_build/builds/pip.sh')
-rwxr-xr-x | tensorflow/tools/ci_build/builds/pip.sh | 286 |
1 files changed, 74 insertions, 212 deletions
diff --git a/tensorflow/tools/ci_build/builds/pip.sh b/tensorflow/tools/ci_build/builds/pip.sh index 66ebf13baa..16364fbf9e 100755 --- a/tensorflow/tools/ci_build/builds/pip.sh +++ b/tensorflow/tools/ci_build/builds/pip.sh @@ -13,55 +13,27 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================== - -# Build the Python PIP installation package for TensorFlow -# and run the Python unit tests from the source code on the installation +# +# Build the Python PIP installation package for TensorFlow and install +# the package. +# The PIP installation is done using the --user flag. # # Usage: -# pip.sh CONTAINER_TYPE +# pip.sh CONTAINER_TYPE [--test_tutorials] # # When executing the Python unit tests, the script obeys the shell -# variables: PY_TEST_WHITELIST, PY_TEST_BLACKLIST, PY_TEST_GPU_BLACKLIST, -# and NO_TEST_ON_INSTALL -# -# To select only a subset of the Python tests to run, set the environment -# variable PY_TEST_WHITELIST, e.g., -# PY_TEST_WHITELIST="tensorflow/python/kernel_tests/shape_ops_test.py" -# Separate the tests with a colon (:). Leave this environment variable empty -# to disable the whitelist. +# variables: TF_BUILD_BAZEL_CLEAN, NO_TEST_ON_INSTALL # -# You can also ignore a set of the tests by using the environment variable -# PY_TEST_BLACKLIST. For example, you can include in PY_TEST_BLACKLIST the -# tests that depend on Python modules in TensorFlow source that are not -# exported publicly. +# TF_BUILD_BAZEL_CLEAN, if set to any non-empty and non-0 value, directs the +# script to perform bazel clean prior to main build and test steps. # -# In addition, you can put blacklist for only GPU build inthe environment -# variable PY_TEST_GPU_BLACKLIST. -# -# If the environmental variable NO_TEST_ON_INSTALL is set to any non-empty -# value, the script will exit after the pip install step. - -# ============================================================================= -# Test blacklist: General +# If NO_TEST_ON_INSTALL has any non-empty and non-0 value, the test-on-install +# part will be skipped. # -# tensorflow/python/framework/ops_test.py -# depends on depends on "test_ops", which is defined in a C++ file wrapped as -# a .py file through the Bazel rule “tf_gen_ops_wrapper_py”. -# tensorflow/util/protobuf/compare_test.py: -# depends on compare_test_pb2 defined outside Python -# tensorflow/python/framework/device_test.py: -# depends on CheckValid() and ToString(), both defined externally +# I the --test_tutorials flag is set, it will cause the script to run the +# tutorial tests (see test_tutorials.sh) after the PIP +# installation and the Python unit tests-on-install step. # -PY_TEST_BLACKLIST="${PY_TEST_BLACKLIST}:"\ -"tensorflow/python/framework/ops_test.py:"\ -"tensorflow/python/util/protobuf/compare_test.py:"\ -"tensorflow/python/framework/device_test.py" - -# Test blacklist: GPU-only -PY_TEST_GPU_BLACKLIST="${PY_TEST_GPU_BLACKLIST}:"\ -"tensorflow/python/framework/function_test.py" - -# ============================================================================= # Helper functions # Get the absolute path from a path @@ -69,15 +41,30 @@ abs_path() { [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}" } + # Exit after a failure die() { echo $@ exit 1 } + # Get the command line arguments CONTAINER_TYPE=$( echo "$1" | tr '[:upper:]' '[:lower:]' ) +if [[ ! -z "${TF_BUILD_BAZEL_CLEAN}" ]] && \ + [[ "${TF_BUILD_BAZEL_CLEAN}" != "0" ]]; then + echo "TF_BUILD_BAZEL_CLEAN=${TF_BUILD_BAZEL_CLEAN}: Performing 'bazel clean'" + bazel clean +fi + +DO_TEST_TUTORIALS=0 +for ARG in $@; do + if [[ "${ARG}" == "--test_tutorials" ]]; then + DO_TEST_TUTORIALS=1 + fi +done + PIP_BUILD_TARGET="//tensorflow/tools/pip_package:build_pip_package" if [[ ${CONTAINER_TYPE} == "cpu" ]]; then bazel build -c opt ${PIP_BUILD_TARGET} || die "Build failed." @@ -96,6 +83,12 @@ if [[ ${CONTAINER_TYPE} == "gpu" ]]; then PY_TEST_BLACKLIST="${PY_TEST_BLACKLIST}:${PY_TEST_GPU_BLACKLIST}" fi +# If still in a virtualenv, deactivate it first +if [[ ! -z "$(which deactivate)" ]]; then + echo "It appears that we are already in a virtualenv. Deactivating..." + deactivate || die "FAILED: Unable to deactivate from existing virtualenv" +fi + # Obtain the path to Python binary source tools/python_bin_path.sh @@ -109,18 +102,20 @@ fi # installation of Python PY_MAJOR_MINOR_VER=$(${PYTHON_BIN_PATH} -V 2>&1 | awk '{print $NF}' | cut -d. -f-2) -echo "Python binary path to be used in PIP install-test: ${PYTHON_BIN_PATH} "\ +echo "Python binary path to be used in PIP install: ${PYTHON_BIN_PATH} "\ "(Major.Minor version: ${PY_MAJOR_MINOR_VER})" # Build PIP Wheel file -PIP_WHL_DIR="pip_test/whl" -PIP_WHL_DIR=`abs_path ${PIP_WHL_DIR}` # Get absolute path +PIP_TEST_ROOT="pip_test" +PIP_WHL_DIR="${PIP_TEST_ROOT}/whl" +PIP_WHL_DIR=$(abs_path ${PIP_WHL_DIR}) # Get absolute path rm -rf ${PIP_WHL_DIR} && mkdir -p ${PIP_WHL_DIR} -bazel-bin/tensorflow/tools/pip_package/build_pip_package ${PIP_WHL_DIR} && +bazel-bin/tensorflow/tools/pip_package/build_pip_package ${PIP_WHL_DIR} || \ +die "build_pip_package FAILED" # Perform installation -WHL_PATH=`ls ${PIP_WHL_DIR}/tensorflow*.whl` -if [[ `echo ${WHL_PATH} | wc -w` -ne 1 ]]; then +WHL_PATH=$(ls ${PIP_WHL_DIR}/tensorflow*.whl) +if [[ $(echo ${WHL_PATH} | wc -w) -ne 1 ]]; then die "ERROR: Failed to find exactly one built TensorFlow .whl file in "\ "directory: ${PIP_WHL_DIR}" fi @@ -130,180 +125,47 @@ echo "whl file path = ${WHL_PATH}" # Install, in user's local home folder echo "Installing pip whl file: ${WHL_PATH}" -# Call pip install twice, first time with --upgrade and second time without it -# This addresses the sporadic test failures related to protobuf version -${PYTHON_BIN_PATH} -m pip install -v --user --upgrade ${WHL_PATH} numpy==1.8.2 && -${PYTHON_BIN_PATH} -m pip install -v --user ${WHL_PATH} && +# Create temporary directory for install test +VENV_DIR="${PIP_TEST_ROOT}/venv" +rm -rf "${VENV_DIR}" && mkdir -p "${VENV_DIR}" +echo "Create directory for virtualenv: ${VENV_DIR}" + +# Verify that virtualenv exists +if [[ -z $(which virtualenv) ]]; then + die "FAILED: virtualenv not available on path" +fi + +virtualenv -p "${PYTHON_BIN_PATH}" "${VENV_DIR}" || +die "FAILED: Unable to create virtualenv" + +source "${VENV_DIR}/bin/activate" || +die "FAILED: Unable to activate virtualenv" + +# Install the pip file in virtual env +pip install -v ${WHL_PATH} \ +&& echo "Successfully installed pip package ${WHL_PATH}" \ +|| die "pip install (without --upgrade) FAILED" # If NO_TEST_ON_INSTALL is set to any non-empty value, skip all Python # tests-on-install and exit right away -if [[ ! -z ${NO_TEST_ON_INSTALL} ]]; then +if [[ ! -z "${NO_TEST_ON_INSTALL}" ]] && + [[ "${NO_TEST_ON_INSTALL}" != "0" ]]; then echo "NO_TEST_ON_INSTALL=${NO_TEST_ON_INSTALL}:" echo " Skipping ALL Python unit tests on install" exit 0 fi -# Directory from which the unit-test files will be run -PY_TEST_DIR_REL="pip_test/tests" -PY_TEST_DIR=`abs_path ${PY_TEST_DIR_REL}` # Get absolute path -rm -rf ${PY_TEST_DIR} && mkdir -p ${PY_TEST_DIR} - -# Create test log directory -PY_TEST_LOG_DIR_REL=${PY_TEST_DIR_REL}/logs -PY_TEST_LOG_DIR=`abs_path ${PY_TEST_LOG_DIR_REL}` # Absolute path - -mkdir ${PY_TEST_LOG_DIR} - -# Copy source files that are required by the tests but are not included in the -# PIP package - -# Look for local Python library directory -LIB_PYTHON_DIR="" +# Call test_installation.sh to perform test-on-install +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -# Candidate locations of the local Python library directory -LIB_PYTHON_DIR_CANDS="${HOME}/.local/lib/python${PY_MAJOR_MINOR_VER}* "\ -"${HOME}/Library/Python/${PY_MAJOR_MINOR_VER}*/lib/python" +"${DIR}/test_installation.sh" --virtualenv || +die "PIP tests-on-install FAILED" -for CAND in ${LIB_PYTHON_DIR_CANDS}; do - if [[ -d "${CAND}" ]]; then - LIB_PYTHON_DIR="${CAND}" - break - fi -done - -if [[ -z ${LIB_PYTHON_DIR} ]]; then - die "Failed to find local Python library directory" -else - echo "Found local Python library directory at: ${LIB_PYTHON_DIR}" +# Optional: Run the tutorial tests +if [[ "${DO_TEST_TUTORIALS}" == "1" ]]; then + "${DIR}/test_tutorials.sh" --virtualenv || +die "PIP tutorial tests-on-install FAILED" fi -PACKAGES_DIR=`ls -d ${LIB_PYTHON_DIR}/*-packages | head -1` - -echo "Copying some source directories that are required by tests but are "\ -"not included in install to Python packages directory: ${PACKAGES_DIR}" - -# tensorflow.python.tools -rm -rf ${PACKAGES_DIR}/tensorflow/python/tools -cp -r tensorflow/python/tools \ - ${PACKAGES_DIR}/tensorflow/python/tools -touch ${PACKAGES_DIR}/tensorflow/python/tools/__init__.py # Make module visible - -echo "Copying additional files required by tests to working directory "\ -"for test: ${PY_TEST_DIR}" - -# Image files required by some tests, e.g., images_ops_test.py -mkdir -p ${PY_TEST_DIR}/tensorflow/core/lib -rm -rf ${PY_TEST_DIR}/tensorflow/core/lib/jpeg -cp -r tensorflow/core/lib/jpeg ${PY_TEST_DIR}/tensorflow/core/lib -rm -rf ${PY_TEST_DIR}/tensorflow/core/lib/png -cp -r tensorflow/core/lib/png ${PY_TEST_DIR}/tensorflow/core/lib - -# Run tests -DIR0=`pwd` -ALL_PY_TESTS=`find tensorflow/python -name "*_test.py"` -# TODO(cais): Add tests in tensorflow/contrib - -PY_TEST_COUNT=`echo ${ALL_PY_TESTS} | wc -w` - -if [[ ${PY_TEST_COUNT} -eq 0 ]]; then - die "ERROR: Cannot find any tensorflow Python unit tests to run on install" -fi - -# Iterate through all the Python unit test files using the installation -COUNTER=0 -PASS_COUNTER=0 -FAIL_COUNTER=0 -SKIP_COUNTER=0 -FAILED_TESTS="" -FAILED_TEST_LOGS="" - -for TEST_FILE_PATH in ${ALL_PY_TESTS}; do - ((COUNTER++)) - - PROG_STR="(${COUNTER} / ${PY_TEST_COUNT})" - - # If PY_TEST_WHITELIST is not empty, only the white-listed tests will be run - if [[ ! -z ${PY_TEST_WHITELIST} ]] && \ - [[ ! ${PY_TEST_WHITELIST} == *"${TEST_FILE_PATH}"* ]]; then - ((SKIP_COUNTER++)) - echo "${PROG_STR} Non-whitelisted test SKIPPED: ${TEST_FILE_PATH}" - continue - fi - - # If the test is in the black list, skip it - if [[ ${PY_TEST_BLACKLIST} == *"${TEST_FILE_PATH}"* ]]; then - ((SKIP_COUNTER++)) - echo "${PROG_STR} Blacklisted test SKIPPED: ${TEST_FILE_PATH}" - continue - fi - - # Copy to a separate directory to guard against the possibility of picking up - # modules in the source directory - cp ${TEST_FILE_PATH} ${PY_TEST_DIR}/ - - TEST_BASENAME=`basename "${TEST_FILE_PATH}"` - - # Relative path of the test log. Use long path in case there are duplicate - # file names in the Python tests - TEST_LOG_REL="${PY_TEST_LOG_DIR_REL}/${TEST_FILE_PATH}.log" - mkdir -p `dirname ${TEST_LOG_REL}` # Create directory for log - - TEST_LOG=`abs_path ${TEST_LOG_REL}` # Absolute path - - # Before running the test, cd away from the Tensorflow source to - # avoid the possibility of picking up dependencies from the - # source directory - cd ${PY_TEST_DIR} - ${PYTHON_BIN_PATH} ${PY_TEST_DIR}/${TEST_BASENAME} >${TEST_LOG} 2>&1 - - # Check for pass or failure status of the test outtput and exit - if [[ $? -eq 0 ]]; then - ((PASS_COUNTER++)) - - echo "${PROG_STR} Python test-on-install PASSED: ${TEST_FILE_PATH}" - else - ((FAIL_COUNTER++)) - - FAILED_TESTS="${FAILED_TESTS} ${TEST_FILE_PATH}" - - FAILED_TEST_LOGS="${FAILED_TEST_LOGS} ${TEST_LOG_REL}" - - echo "${PROG_STR} Python test-on-install FAILED: ${TEST_FILE_PATH}" - echo " Log @: ${TEST_LOG_REL}" - echo "============== BEGINS failure log content ==============" - cat ${TEST_LOG} - echo "============== ENDS failure log content ==============" - echo "" - fi - cd ${DIR0} - - # Clean up files for this test - rm -f ${PY_TEST_DIR}/${TEST_BASENAME} - -done - -echo "" -echo "${PY_TEST_COUNT} Python test(s):" \ - "${PASS_COUNTER} passed;" \ - "${FAIL_COUNTER} failed; " \ - "${SKIP_COUNTER} skipped" -echo "Test logs directory: ${PY_TEST_LOG_DIR_REL}" - -if [[ ${FAIL_COUNTER} -eq 0 ]]; then - echo "" - echo "Python test-on-install SUCCEEDED" - - exit 0 -else - echo "FAILED test(s):" - FAILED_TEST_LOGS=($FAILED_TEST_LOGS) - FAIL_COUNTER=0 - for TEST_NAME in ${FAILED_TESTS}; do - echo " ${TEST_NAME} (Log @: ${FAILED_TEST_LOGS[${FAIL_COUNTER}]})" - ((FAIL_COUNTER++)) - done - - echo "" - echo "Python test-on-install FAILED" - exit 1 -fi +deactivate || +die "FAILED: Unable to deactivate virtualenv" |