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