def test_modules(): mod1 = Module( root=Path('mod1'), raw_setup={ 'name': 'module1', 'version': '1.2.3.dev', 'url': 'http://github.com/quantumlib/cirq', 'author': 'The Cirq Developers', 'author_email': '*****@*****.**', 'python_requires': '>=3.6.0', 'install_requires': ['req1', 'req2'], 'license': 'Apache 2', 'packages': ['pack1', 'pack1.sub'], }, ) assert mod1.name == 'module1' assert mod1.version == '1.2.3.dev' assert mod1.top_level_packages == ['pack1'] assert mod1.top_level_package_paths == [Path('mod1') / 'pack1'] assert mod1.install_requires == ['req1', 'req2'] mod2 = Module( root=Path('mod2'), raw_setup={ 'name': 'module2', 'version': '1.2.3.dev', 'packages': ['pack2'] }, ) assert mod2.name == 'module2' assert mod2.version == '1.2.3.dev' assert mod2.top_level_packages == ['pack2'] assert mod2.top_level_package_paths == [Path('mod2') / 'pack2'] assert mod2.install_requires == [] assert modules.list_modules( search_dir=Path("dev_tools/modules_test_data")) == [mod1, mod2] parent = Module( root=Path('.'), raw_setup={ 'name': 'parent-module', 'version': '1.2.3.dev', 'requirements': [] }, ) assert parent.top_level_packages == [] assert modules.list_modules(search_dir=Path("dev_tools/modules_test_data"), include_parent=True) == [ mod1, mod2, parent, ]
PACKAGES = [ "-r", "dev_tools/requirements/deps/pytest.txt", "-r", # one of the _compat_test.py tests uses flynt for testing metadata "dev_tools/requirements/deps/flynt.txt", ] @pytest.mark.slow # ensure that no cirq packages are on the PYTHONPATH, this is important, otherwise # the "isolation" fails and for example cirq-core would be on the PATH @mock.patch.dict(os.environ, {"PYTHONPATH": ""}) @pytest.mark.parametrize('module', list_modules(), ids=[m.name for m in list_modules()]) def test_isolated_packages(cloned_env, module): env = cloned_env("isolated_packages", *PACKAGES) if str(module.root) != "cirq-core": assert f'cirq-core=={module.version}' in module.install_requires result = shell_tools.run_cmd( *f"{env}/bin/pip install ./{module.root} ./cirq-core".split(), err=shell_tools.TeeCapture(), raise_on_fail=False, ) assert result.exit_code == 0, f"Failed to install {module.name}:\n{result.err}" result = shell_tools.run_cmd(
def test_versions_are_the_same(): mods = modules.list_modules(include_parent=True) versions = {m.name: m.version for m in mods} assert len(set(versions.values()) ) == 1, f"Versions should be the same, instead: \n{versions}"
# it will be a pre-release version on PyPi. See # https://packaging.python.org/guides/distributing-packages-using-setuptools/#pre-release-versioning # for more details. if 'CIRQ_PRE_RELEASE_VERSION' in os.environ: __version__ = os.environ['CIRQ_PRE_RELEASE_VERSION'] long_description = ( "**This is a development version of Cirq and may be " "unstable.**\n\n**For the latest stable release of Cirq " "see**\n`here <https://pypi.org/project/cirq>`__.\n\n" + long_description) # Sanity check assert __version__, 'Version string cannot be empty' # This is a pure metapackage that installs all our packages requirements = [f'{p.name}=={p.version}' for p in modules.list_modules()] dev_requirements = explode('dev_tools/requirements/deps/dev-tools.txt') dev_requirements = [r.strip() for r in dev_requirements] setup( name=name, version=__version__, url='http://github.com/quantumlib/cirq', author='The Cirq Developers', author_email='*****@*****.**', python_requires=('>=3.6.0'), install_requires=requirements, extras_require={ 'dev_env': dev_requirements, },
from dev_tools.modules import list_modules PACKAGES = [ "-r", "dev_tools/requirements/deps/pytest.txt", "-r", # one of the _compat_test.py tests uses flynt for testing metadata "dev_tools/requirements/deps/flynt.txt", ] @pytest.mark.slow # ensure that no cirq packages are on the PYTHONPATH, this is important, otherwise # the "isolation" fails and for example cirq-core would be on the PATH @mock.patch.dict(os.environ, {"PYTHONPATH": ""}) @pytest.mark.parametrize('module', list_modules(), ids=[m.name for m in list_modules()]) def test_isolated_packages(cloned_env, module): env = cloned_env("isolated_packages", *PACKAGES) if str(module.root) != "cirq-core": assert f'cirq-core=={module.version}' in module.install_requires result = shell_tools.run_cmd( *f"{env}/bin/pip install ./{module.root} ./cirq-core".split(), err=shell_tools.TeeCapture(), raise_on_fail=False, ) assert result.exit_code == 0, f"Failed to install {module.name}:\n{result.err}" result = shell_tools.run_cmd( *f"{env}/bin/pytest ./{module.root} --ignore ./cirq-core/cirq/contrib".split(),