1#!/usr/bin/env bash 2# Copyright 2018 gRPC 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 16set -ex 17 18cd "$(dirname "$0")" 19 20shopt -s nullglob 21 22if [[ "$1" == "binary" ]] 23then 24 echo "Testing Python binary distribution" 25 ARCHIVES=("$EXTERNAL_GIT_ROOT"/input_artifacts/grpcio-[0-9]*.whl) 26 TOOLS_ARCHIVES=("$EXTERNAL_GIT_ROOT"/input_artifacts/grpcio_tools-[0-9]*.whl) 27else 28 echo "Testing Python source distribution" 29 ARCHIVES=("$EXTERNAL_GIT_ROOT"/input_artifacts/grpcio-[0-9]*.tar.gz) 30 TOOLS_ARCHIVES=("$EXTERNAL_GIT_ROOT"/input_artifacts/grpcio-tools-[0-9]*.tar.gz) 31fi 32 33HEALTH_ARCHIVES=("$EXTERNAL_GIT_ROOT"/input_artifacts/grpcio-health-checking-[0-9]*.tar.gz) 34REFLECTION_ARCHIVES=("$EXTERNAL_GIT_ROOT"/input_artifacts/grpcio-reflection-[0-9]*.tar.gz) 35TESTING_ARCHIVES=("$EXTERNAL_GIT_ROOT"/input_artifacts/grpcio-testing-[0-9]*.tar.gz) 36 37VIRTUAL_ENV=$(mktemp -d) 38virtualenv "$VIRTUAL_ENV" 39PYTHON=$VIRTUAL_ENV/bin/python 40"$PYTHON" -m pip install --upgrade six pip wheel 41 42function validate_wheel_hashes() { 43 for file in "$@"; do 44 "$PYTHON" -m wheel unpack "$file" -d /tmp || return 1 45 done 46 return 0 47} 48 49function at_least_one_installs() { 50 for file in "$@"; do 51 if "$PYTHON" -m pip install "$file"; then 52 return 0 53 fi 54 done 55 return 1 56} 57 58 59# 60# Validate the files in wheel matches their hashes and size in RECORD 61# 62 63if [[ "$1" == "binary" ]]; then 64 validate_wheel_hashes "${ARCHIVES[@]}" 65 validate_wheel_hashes "${TOOLS_ARCHIVES[@]}" 66fi 67 68 69# 70# Install our distributions in order of dependencies 71# 72 73at_least_one_installs "${ARCHIVES[@]}" 74at_least_one_installs "${TOOLS_ARCHIVES[@]}" 75at_least_one_installs "${HEALTH_ARCHIVES[@]}" 76at_least_one_installs "${REFLECTION_ARCHIVES[@]}" 77at_least_one_installs "${TESTING_ARCHIVES[@]}" 78 79 80# 81# Test our distributions 82# 83 84# TODO(jtattermusch): add a .proto file to the distribtest, generate python 85# code from it and then use the generated code from distribtest.py 86"$PYTHON" -m grpc.tools.protoc --help 87 88"$PYTHON" distribtest.py 89