Skip to content

Commit 4960e17

Browse files
authoredJun 21, 2021
Fix extras_require for the cirq metapackage setup.py (quantumlib#4246)
The tensorflow-docs requirement was in the wrong format (worked for pip install but not for extras_require). It also adds testing to avoid these kind of failures: `dev_tools/packaging/packaging_test.sh` is now executed as part of the CI test suite. Fixes quantumlib#4222.
1 parent a2f107c commit 4960e17

File tree

9 files changed

+98
-12
lines changed

9 files changed

+98
-12
lines changed
 

‎.github/workflows/ci.yml

+13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ jobs:
1414
architecture: 'x64'
1515
- name: Misc
1616
run: check/misc
17+
packaging_test:
18+
name: Packaging test
19+
runs-on: ubuntu-20.04
20+
steps:
21+
- uses: actions/checkout@v2
22+
- uses: actions/setup-python@v1
23+
with:
24+
python-version: '3.7'
25+
architecture: 'x64'
26+
- name: Install dependencies
27+
run: pip install -r dev_tools/requirements/deps/packaging.txt
28+
- name: Run packaging test
29+
run: ./dev_tools/packaging/packaging_test.sh
1730
format:
1831
name: Format check
1932
runs-on: ubuntu-20.04

‎MANIFEST.in

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
include requirements.txt
21
include LICENSE

‎dev_tools/modules.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727
optional arguments:
2828
-h, --help show this help message and exit
2929
--mode {folder,package-path}
30-
'folder' to list root folder for module, 'package-path' for top level
31-
python package path
30+
'folder' to list root folder for module (e.g. cirq-google),
31+
'package-path' for top level python package path
32+
(e.g. cirq-google/cirq_google),
33+
'package' for top level python package (e.g cirq_google),
3234
--include-parent whether to include the parent package or not
3335
"""
3436

@@ -41,6 +43,7 @@
4143

4244
_FOLDER = 'folder'
4345
_PACKAGE_PATH = 'package-path'
46+
_PACKAGE = 'package'
4447

4548

4649
@dataclasses.dataclass
@@ -142,6 +145,9 @@ def _print_list_modules(mode: str, include_parent: bool = False):
142145
elif mode == _PACKAGE_PATH:
143146
for p in m.top_level_package_paths:
144147
print(p, end=" ")
148+
elif mode == _PACKAGE:
149+
for package in m.top_level_packages:
150+
print(package, end=" ")
145151

146152

147153
def main(argv: List[str]):
@@ -169,10 +175,11 @@ def _add_list_modules_cmd(subparsers):
169175
list_modules_cmd.add_argument(
170176
"--mode",
171177
default=_FOLDER,
172-
choices=[_FOLDER, _PACKAGE_PATH],
178+
choices=[_FOLDER, _PACKAGE_PATH, _PACKAGE],
173179
type=str,
174-
help="'folder' to list root folder for module,\n"
175-
"'package-path' for top level python package path",
180+
help="'folder' to list root folder for module (e.g. cirq-google),\n"
181+
"'package-path' for top level python package path (e.g. cirq-google/cirq_google),\n"
182+
"'package' for top level python package (e.g cirq_google),\n",
176183
)
177184
list_modules_cmd.add_argument(
178185
"--include-parent",

‎dev_tools/modules_test.py

+4
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ def test_main():
113113
modules.main(["list", "--mode", "folder", "--include-parent"])
114114
assert output.getvalue() == ' '.join(["mod1", "mod2", ".", ""])
115115

116+
with mock.patch('sys.stdout', new=StringIO()) as output:
117+
modules.main(["list", "--mode", "package"])
118+
assert output.getvalue() == ' '.join(["pack1", "pack2", ""])
119+
116120

117121
@chdir(target_dir=None)
118122
def test_error():

‎dev_tools/packaging/packaging_test.sh

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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

‎dev_tools/requirements/deps/dev-tools.txt

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@
55
-r protos.txt
66
-r notebook.txt
77
-r tensorflow-docs.txt
8+
-r packaging.txt
89

910
# For testing and analyzing code.
1011
asv
11-
virtualenv
12-
13-
# For uploading packages to pypi.
14-
twine
1512

1613
# For verifying behavior of Quil output.
1714
pyquil~=2.21.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# for testing packaging in isolation
2+
virtualenv
3+
4+
# for creating packages
5+
setuptools
6+
wheel
7+
8+
# for uploading packages to pypi
9+
twine
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# don't upgrade this just yet, anything later will require protobuf>=3.14
2-
git+https://github.com/tensorflow/docs@a90bcd30eb550f8d4ee335ff3daf18de5ca84b70
2+
tensorflow-docs@git+https://github.com/tensorflow/docs@a90bcd30eb550f8d4ee335ff3daf18de5ca84b70

‎setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
url='http://github.com/quantumlib/cirq',
6363
author='The Cirq Developers',
6464
author_email='cirq-dev@googlegroups.com',
65-
python_requires=('>=3.6.0'),
65+
python_requires='>=3.6.0',
6666
install_requires=requirements,
6767
extras_require={
6868
'dev_env': dev_requirements,

0 commit comments

Comments
 (0)
Please sign in to comment.