1
+ #! /bin/bash
2
+
3
+ # Copyright 2021 The Cirq Developers
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # ###############################################################################
18
+ # This script tests packaging. It creates the packages for all the cirq modules
19
+ # `pip install`s them in a clean virtual environment and then runs some simple
20
+ # verificiations on each of the modules, ensuring that they can be imported.
21
+ # ###############################################################################
22
+
23
+ set -e
24
+
25
+ # Temporary workspace.
26
+ tmp_dir=$( mktemp -d)
27
+ trap " { rm -rf ${tmp_dir} ; }" EXIT
28
+
29
+ # New virtual environment
30
+ echo " Working in a fresh virtualenv at ${tmp_dir} /env"
31
+ virtualenv --quiet " --python=/usr/bin/python3" " ${tmp_dir} /env"
32
+
33
+ export CIRQ_PRE_RELEASE_VERSION=$( dev_tools/packaging/generate-dev-version-id.sh)
34
+ out_dir=${tmp_dir} /dist
35
+ dev_tools/packaging/produce-package.sh ${out_dir} $CIRQ_PRE_RELEASE_VERSION
36
+
37
+ # test installation
38
+ " ${tmp_dir} /env/bin/python" -m pip install ${out_dir} /*
39
+
40
+ echo ===========================
41
+ echo Testing that code executes
42
+ echo ===========================
43
+
44
+ " ${tmp_dir} /env/bin/python" -c " import cirq; print(cirq.google.Foxtail)"
45
+ " ${tmp_dir} /env/bin/python" -c " import cirq_google; print(cirq_google.Foxtail)"
46
+ " ${tmp_dir} /env/bin/python" -c " import cirq; print(cirq.Circuit(cirq.CZ(*cirq.LineQubit.range(2))))"
47
+
48
+ echo =======================================
49
+ echo Testing that all modules are installed
50
+ echo =======================================
51
+
52
+ CIRQ_PACKAGES=$( env PYTHONPATH=. python dev_tools/modules.py list --mode package)
53
+ for p in $CIRQ_PACKAGES ; do
54
+ echo --- Testing $p -----
55
+ python_test=" import $p ; print($p ); assert '${tmp_dir} ' in $p .__file__, 'Package path seems invalid.'"
56
+ env PYTHONPATH=' ' " ${tmp_dir} /env/bin/python" -c " $python_test " && echo -e " \033[32mPASS\033[0m" || echo -e " \033[31mFAIL\033[0m"
57
+ done
0 commit comments