Files
cibuildwheel/test/test_dependency_versions.py
T

141 lines
4.3 KiB
Python
Raw Normal View History

from __future__ import annotations
2022-07-22 11:33:32 +02:00
import platform
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
import sys
2020-05-02 16:54:19 +01:00
versions_output_text = subprocess.check_output(
[sys.executable, '-m', 'pip', 'freeze', '--all', '-qq'],
2020-05-02 16:54:19 +01:00
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)
2024-02-27 21:26:16 +00:00
expected_version = os.environ['EXPECTED_PIP_VERSION']
2024-02-27 21:26:16 +00:00
assert f'pip=={expected_version}' in versions, (
f'error: pip version should equal {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
)
project_with_expected_version_checks.files["pyproject.toml"] = r"""
[build-system]
requires = ["setuptools", "pip"]
build-backend = "setuptools.build_meta"
"""
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 dict(re.findall(VERSION_REGEX, constraint_file_text))
2020-02-18 09:33:07 +00:00
@pytest.mark.parametrize("python_version", ["3.6", "3.8", "3.10"])
2024-06-09 15:45:31 -04:00
def test_pinned_versions(tmp_path, python_version, build_frontend_env_nouv):
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")
if python_version == "3.6" and utils.platform == "macos" and platform.machine() == "arm64":
pytest.skip("macOS arm64 does not support Python 3.6")
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
version_no_dot = python_version.replace(".", "")
2020-02-18 09:33:07 +00:00
build_environment = {}
build_pattern = f"[cp]p{version_no_dot}-*"
constraint_filename = f"constraints-python{version_no_dot}.txt"
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
2024-02-27 21:26:16 +00:00
build_environment["EXPECTED_PIP_VERSION"] = constraint_versions["pip"]
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,
2024-06-09 15:45:31 -04:00
**build_frontend_env_nouv,
2021-04-30 17:56:34 -04:00
},
)
2020-02-18 09:33:07 +00:00
# also check that we got the right wheels
expected_wheels = [
w
for w in utils.expected_wheels("spam", "0.1.0")
if f"-cp{version_no_dot}" in w or f"-pp{version_no_dot}" in w
]
2020-02-18 20:21:08 +00:00
2020-02-18 09:33:07 +00:00
assert set(actual_wheels) == set(expected_wheels)
2024-06-09 15:45:31 -04:00
def test_dependency_constraints_file(tmp_path, build_frontend_env_nouv):
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 = {
2023-05-26 21:14:55 -07:00
"pip": "23.1.2",
"delocate": "0.10.3",
}
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}
delocate=={delocate}
2023-10-27 01:21:20 -04:00
""".format(**tool_versions)
2021-04-30 17:56:34 -04:00
)
)
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),
2023-05-26 21:14:55 -07:00
"CIBW_SKIP": "cp36-*",
2024-06-09 15:45:31 -04:00
**build_frontend_env_nouv,
2021-04-30 17:56:34 -04:00
},
)
# also check that we got the right wheels
2023-05-26 21:14:55 -07:00
expected_wheels = [w for w in utils.expected_wheels("spam", "0.1.0") if "-cp36" not in w]
assert set(actual_wheels) == set(expected_wheels)