Home | History | Annotate | Download | only in python
      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 
     16 set -ex
     17 
     18 cd "$(dirname "$0")"
     19 
     20 shopt -s nullglob
     21 
     22 if [[ "$1" == "binary" ]]
     23 then
     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)
     27 else
     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)
     31 fi
     32 
     33 HEALTH_ARCHIVES=("$EXTERNAL_GIT_ROOT"/input_artifacts/grpcio-health-checking-[0-9]*.tar.gz)
     34 REFLECTION_ARCHIVES=("$EXTERNAL_GIT_ROOT"/input_artifacts/grpcio-reflection-[0-9]*.tar.gz)
     35 TESTING_ARCHIVES=("$EXTERNAL_GIT_ROOT"/input_artifacts/grpcio-testing-[0-9]*.tar.gz)
     36 
     37 VIRTUAL_ENV=$(mktemp -d)
     38 virtualenv "$VIRTUAL_ENV"
     39 PYTHON=$VIRTUAL_ENV/bin/python
     40 "$PYTHON" -m pip install --upgrade six pip
     41 
     42 function at_least_one_installs() {
     43   for file in "$@"; do
     44     if "$PYTHON" -m pip install "$file"; then
     45       return 0
     46     fi
     47   done
     48   return 1
     49 }
     50 
     51 
     52 #
     53 # Install our distributions in order of dependencies
     54 #
     55 
     56 at_least_one_installs "${ARCHIVES[@]}"
     57 at_least_one_installs "${TOOLS_ARCHIVES[@]}"
     58 at_least_one_installs "${HEALTH_ARCHIVES[@]}"
     59 at_least_one_installs "${REFLECTION_ARCHIVES[@]}"
     60 at_least_one_installs "${TESTING_ARCHIVES[@]}"
     61 
     62 
     63 #
     64 # Test our distributions
     65 #
     66 
     67 # TODO(jtattermusch): add a .proto file to the distribtest, generate python
     68 # code from it and then use the generated code from distribtest.py
     69 "$PYTHON" -m grpc.tools.protoc --help
     70 
     71 "$PYTHON" distribtest.py
     72