1#!/bin/bash 2# Copyright 2017 The Abseil Authors. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16# Smoke test to verify setup.py works as expected. 17# Note on Windows, this must run via msys. 18 19# Fail on any error. Treat unset variables an error. Print commands as executed. 20set -eux 21 22if [[ "$#" -ne "2" ]]; then 23 echo 'Must specify the Python interpreter and virtualenv path.' 24 echo 'Usage:' 25 echo ' smoke_tests/smoke_test.sh [Python interpreter path] [virtualenv Path]' 26 exit 1 27fi 28 29ABSL_PYTHON=$1 30ABSL_VIRTUALENV=$2 31TMP_DIR=$(mktemp -d) 32trap "{ rm -rf ${TMP_DIR}; }" EXIT 33# Do not bootstrap pip/setuptools, they are manually installed with get-pip.py 34# inside the virtualenv. 35if ${ABSL_VIRTUALENV} --help | grep '\--no-site-packages'; then 36 no_site_packages_flag="--no-site-packages" 37else 38 # --no-site-packages becomes the default in version 20 and is no longer a 39 # flag. 40 no_site_packages_flag="" 41fi 42${ABSL_VIRTUALENV} ${no_site_packages_flag} --no-pip --no-setuptools --no-wheel \ 43 -p ${ABSL_PYTHON} ${TMP_DIR} 44 45# Temporarily disable unbound variable errors to activate virtualenv. 46set +u 47if [[ $(uname -s) == MSYS* ]]; then 48 source ${TMP_DIR}/Scripts/activate 49else 50 source ${TMP_DIR}/bin/activate 51fi 52set -u 53 54trap 'deactivate' EXIT 55 56# When running macOS <= 10.12, pip 9.0.3 is required to connect to PyPI. 57# So we need to manually use the latest pip to install absl-py. See: 58# https://mail.python.org/pipermail/distutils-sig/2018-April/032114.html 59if [[ "$(python -c "import sys; print(sys.version_info.major, sys.version_info.minor)")" == "3 6" ]]; then 60 # Latest get-pip.py no longer supports Python 3.6. 61 curl https://bootstrap.pypa.io/pip/3.6/get-pip.py | python 62else 63 curl https://bootstrap.pypa.io/get-pip.py | python 64fi 65pip --version 66 67python --version 68python setup.py install 69python smoke_tests/sample_app.py --echo smoke 2>&1 |grep 'echo is smoke.' 70python smoke_tests/sample_test.py 2>&1 | grep 'msg_for_test' 71