Debian Codegraph @

test/distrib/python/test_packages.sh

raw
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 python3 -m virtualenv "$VIRTUAL_ENV"
39 PYTHON=$VIRTUAL_ENV/bin/python
40 "$PYTHON" -m pip install --upgrade six pip wheel
41
42 function 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
49 function 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
63 if [[ "$1" == "binary" ]]; then
64 validate_wheel_hashes "${ARCHIVES[@]}"
65 validate_wheel_hashes "${TOOLS_ARCHIVES[@]}"
66 fi
67
68
69 #
70 # Install our distributions in order of dependencies
71 #
72
73 at_least_one_installs "${ARCHIVES[@]}"
74 at_least_one_installs "${TOOLS_ARCHIVES[@]}"
75 at_least_one_installs "${HEALTH_ARCHIVES[@]}"
76 at_least_one_installs "${REFLECTION_ARCHIVES[@]}"
77 at_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