Files
cibuildwheel/test/test_dependency_versions.py
T

162 lines
5.0 KiB
Python
Raw Normal View History

2020-02-18 09:33:07 +00:00
import re
import textwrap
2021-01-06 13:50:58 -05:00
import pytest
import cibuildwheel.util
2020-02-18 09:33:07 +00:00
2021-01-06 13:50:58 -05:00
from . import test_projects, utils
2020-05-02 16:54:19 +01:00
project_with_expected_version_checks = test_projects.new_c_project(
2021-04-30 17:56:34 -04:00
setup_py_add=textwrap.dedent(
2021-05-03 11:45:43 -04:00
r"""
2020-05-02 16:54:19 +01:00
import subprocess
import os
versions_output_text = subprocess.check_output(
['pip', 'freeze', '--all', '-qq'],
universal_newlines=True,
)
versions = versions_output_text.strip().splitlines()
# `versions` now looks like:
# ['pip==x.x.x', 'setuptools==x.x.x', 'wheel==x.x.x']
print('Gathered versions', versions)
for package_name in ['pip', 'setuptools', 'wheel']:
env_name = 'EXPECTED_{}_VERSION'.format(package_name.upper())
expected_version = os.environ[env_name]
assert '{}=={}'.format(package_name, expected_version) in versions, (
'error: {} version should equal {}'.format(package_name, expected_version)
)
2021-05-03 11:45:43 -04:00
"""
2021-04-30 17:56:34 -04:00
)
2020-05-02 16:54:19 +01:00
)
2020-02-18 09:33:07 +00:00
2021-05-03 11:45:43 -04:00
VERSION_REGEX = r"([\w-]+)==([^\s]+)"
2020-02-18 09:33:07 +00:00
2020-03-01 12:32:41 +00:00
def get_versions_from_constraint_file(constraint_file):
2021-05-03 11:45:43 -04:00
constraint_file_text = constraint_file.read_text(encoding="utf8")
2020-02-18 09:33:07 +00:00
return {
2021-04-30 17:56:34 -04:00
package: version for package, version in re.findall(VERSION_REGEX, constraint_file_text)
}
2020-02-18 09:33:07 +00:00
2021-02-14 20:44:20 +01:00
@pytest.mark.parametrize("python_version", ["3.6", "3.8", "3.9"])
2021-06-23 10:47:18 -04:00
def test_pinned_versions(tmp_path, python_version, build_frontend_env):
2021-05-03 11:45:43 -04:00
if utils.platform == "linux":
pytest.skip("linux doesn't pin individual tool versions, it pins manylinux images instead")
2020-02-18 09:33:07 +00:00
2021-05-03 11:45:43 -04:00
project_dir = tmp_path / "project"
2020-05-02 16:54:19 +01:00
project_with_expected_version_checks.generate(project_dir)
2020-02-18 09:33:07 +00:00
build_environment = {}
2021-02-14 20:44:20 +01:00
if python_version == "3.6":
2021-05-03 11:45:43 -04:00
constraint_filename = "constraints-python36.txt"
build_pattern = "[cp]p36-*"
elif python_version == "3.7":
constraint_filename = "constraints-python37.txt"
build_pattern = "[cp]p37-*"
2021-02-14 20:44:20 +01:00
elif python_version == "3.8":
constraint_filename = "constraints-python38.txt"
build_pattern = "[cp]p38-*"
2020-02-18 09:33:07 +00:00
else:
2021-05-03 11:45:43 -04:00
constraint_filename = "constraints.txt"
2021-02-14 20:44:20 +01:00
build_pattern = "[cp]p39-*"
2020-02-18 09:33:07 +00:00
2020-06-18 02:00:30 +02:00
constraint_file = cibuildwheel.util.resources_dir / constraint_filename
2020-03-01 12:32:41 +00:00
constraint_versions = get_versions_from_constraint_file(constraint_file)
2020-02-18 09:33:07 +00:00
2021-05-03 11:45:43 -04:00
for package in ["pip", "setuptools", "wheel", "virtualenv"]:
env_name = f"EXPECTED_{package.upper()}_VERSION"
2020-03-01 12:32:41 +00:00
build_environment[env_name] = constraint_versions[package]
2020-02-18 09:33:07 +00:00
2021-05-03 11:45:43 -04:00
cibw_environment_option = " ".join(f"{k}={v}" for k, v in build_environment.items())
2020-02-18 09:33:07 +00:00
# build and test the wheels
2021-04-30 17:56:34 -04:00
actual_wheels = utils.cibuildwheel_run(
project_dir,
add_env={
2021-05-03 11:45:43 -04:00
"CIBW_BUILD": build_pattern,
"CIBW_ENVIRONMENT": cibw_environment_option,
2021-06-23 10:47:18 -04:00
**build_frontend_env,
2021-04-30 17:56:34 -04:00
},
)
2020-02-18 09:33:07 +00:00
# also check that we got the right wheels
2021-02-14 20:44:20 +01:00
if python_version == "3.6":
2021-04-30 17:56:34 -04:00
expected_wheels = [
2021-05-03 11:45:43 -04:00
w for w in utils.expected_wheels("spam", "0.1.0") if "-cp36" in w or "-pp36" in w
2021-04-30 17:56:34 -04:00
]
2021-05-03 11:45:43 -04:00
elif python_version == "3.8":
2021-04-30 17:56:34 -04:00
expected_wheels = [
2021-05-03 11:45:43 -04:00
w for w in utils.expected_wheels("spam", "0.1.0") if "-cp38" in w or "-pp38" in w
2021-04-30 17:56:34 -04:00
]
2021-02-14 20:44:20 +01:00
elif python_version == "3.9":
expected_wheels = [
w for w in utils.expected_wheels("spam", "0.1.0") if "-cp39" in w or "-pp39" in w
]
else:
2021-05-03 11:45:43 -04:00
raise ValueError("unhandled python version")
2020-02-18 20:21:08 +00:00
2020-02-18 09:33:07 +00:00
assert set(actual_wheels) == set(expected_wheels)
2021-06-23 10:47:18 -04:00
def test_dependency_constraints_file(tmp_path, build_frontend_env):
2021-05-03 11:45:43 -04:00
if utils.platform == "linux":
pytest.skip("linux doesn't pin individual tool versions, it pins manylinux images instead")
2021-05-03 11:45:43 -04:00
project_dir = tmp_path / "project"
2020-05-02 16:54:19 +01:00
project_with_expected_version_checks.generate(project_dir)
tool_versions = {
2021-05-03 11:45:43 -04:00
"pip": "20.0.2",
2021-02-14 20:44:20 +01:00
"setuptools": "53.0.0",
2021-05-03 11:45:43 -04:00
"wheel": "0.34.2",
2021-06-23 10:47:18 -04:00
"virtualenv": "20.0.35",
}
constraints_file = tmp_path / "constraints file.txt"
2021-04-30 17:56:34 -04:00
constraints_file.write_text(
textwrap.dedent(
2021-05-03 11:45:43 -04:00
"""
pip=={pip}
setuptools=={setuptools}
wheel=={wheel}
virtualenv=={virtualenv}
2021-06-23 10:47:18 -04:00
importlib-metadata<3,>=0.12; python_version < "3.8"
2021-05-03 11:45:43 -04:00
""".format(
2021-04-30 17:56:34 -04:00
**tool_versions
)
)
)
build_environment = {}
for package_name, version in tool_versions.items():
2021-05-03 11:45:43 -04:00
env_name = f"EXPECTED_{package_name.upper()}_VERSION"
build_environment[env_name] = version
2021-05-03 11:45:43 -04:00
cibw_environment_option = " ".join(f"{k}={v}" for k, v in build_environment.items())
# build and test the wheels
2021-04-30 17:56:34 -04:00
actual_wheels = utils.cibuildwheel_run(
project_dir,
add_env={
2021-05-03 11:45:43 -04:00
"CIBW_ENVIRONMENT": cibw_environment_option,
"CIBW_DEPENDENCY_VERSIONS": str(constraints_file),
2021-06-23 10:47:18 -04:00
**build_frontend_env,
2021-04-30 17:56:34 -04:00
},
)
# also check that we got the right wheels
2021-02-14 20:44:20 +01:00
expected_wheels = utils.expected_wheels("spam", "0.1.0")
assert set(actual_wheels) == set(expected_wheels)