fix: don't constrain build-system.requires with our dependency-versions (#2583)
* Don't constrain build-system.requires with dependency-versions * Remove setting of VIRTUALENV_PIP (it doesn't appear to have any effect) * Alter tests to assert the versions in before_build, not setup.py * Skip the util-test on linux --------- Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
This commit is contained in:
co-authored by
Henry Schreiner
parent
8c5b02f42c
commit
1f2f8b28d5
@@ -1,5 +1,7 @@
|
||||
import json
|
||||
import platform
|
||||
import re
|
||||
import subprocess
|
||||
import textwrap
|
||||
from pathlib import Path
|
||||
|
||||
@@ -9,40 +11,62 @@ from cibuildwheel.util import resources
|
||||
|
||||
from . import test_projects, utils
|
||||
|
||||
project_with_expected_version_checks = test_projects.new_c_project(
|
||||
setup_py_add=textwrap.dedent(
|
||||
r"""
|
||||
import subprocess
|
||||
import os
|
||||
import sys
|
||||
VERSION_REGEX = r"([\w-]+)==([^\s]+)"
|
||||
|
||||
versions_output_text = subprocess.check_output(
|
||||
[sys.executable, '-m', 'pip', 'freeze', '--all', '-qq'],
|
||||
universal_newlines=True,
|
||||
)
|
||||
versions = versions_output_text.strip().splitlines()
|
||||
CHECK_VERSIONS_SCRIPT = """\
|
||||
'''
|
||||
Checks that the versions in the env var EXPECTED_VERSIONS match those
|
||||
installed in the active venv.
|
||||
'''
|
||||
import os, subprocess, sys, json
|
||||
|
||||
# `versions` now looks like:
|
||||
# ['pip==x.x.x', 'setuptools==x.x.x', 'wheel==x.x.x']
|
||||
|
||||
print('Gathered versions', versions)
|
||||
|
||||
expected_version = os.environ['EXPECTED_PIP_VERSION']
|
||||
|
||||
assert f'pip=={expected_version}' in versions, (
|
||||
f'error: pip version should equal {expected_version}'
|
||||
)
|
||||
"""
|
||||
)
|
||||
versions_raw = json.loads(
|
||||
subprocess.check_output([
|
||||
sys.executable, '-m', 'pip', 'list', '--format=json',
|
||||
], text=True)
|
||||
)
|
||||
versions = {item['name']: item['version'] for item in versions_raw}
|
||||
expected_versions = json.loads(os.environ['EXPECTED_VERSIONS'])
|
||||
|
||||
project_with_expected_version_checks.files["pyproject.toml"] = r"""
|
||||
[build-system]
|
||||
requires = ["setuptools", "pip"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
for name, expected_version in expected_versions.items():
|
||||
if name not in versions:
|
||||
continue
|
||||
if versions[name] != expected_version:
|
||||
raise SystemExit(f'error: {name} version should equal {expected_version}. Versions: {versions}')
|
||||
"""
|
||||
|
||||
VERSION_REGEX = r"([\w-]+)==([^\s]+)"
|
||||
|
||||
def test_check_versions_script(tmp_path, build_frontend_env_nouv, capfd):
|
||||
if utils.get_platform() == "linux":
|
||||
pytest.skip("we don't test dependency versions on linux, refer to other tests")
|
||||
|
||||
# sanity check that the CHECK_VERSIONS_SCRIPT fails when it should
|
||||
project_dir = tmp_path / "project"
|
||||
test_projects.new_c_project().generate(project_dir)
|
||||
|
||||
expected_versions = {
|
||||
"pip": "0.0.1",
|
||||
"build": "0.0.2",
|
||||
}
|
||||
script = project_dir / "check_versions.py"
|
||||
script.write_text(CHECK_VERSIONS_SCRIPT)
|
||||
|
||||
with pytest.raises(subprocess.CalledProcessError):
|
||||
utils.cibuildwheel_run(
|
||||
project_dir,
|
||||
add_env={
|
||||
"CIBW_BEFORE_BUILD": f"python {script.name}",
|
||||
"EXPECTED_VERSIONS": json.dumps(expected_versions),
|
||||
**build_frontend_env_nouv,
|
||||
},
|
||||
)
|
||||
|
||||
captured = capfd.readouterr()
|
||||
|
||||
assert (
|
||||
"error: pip version should equal 0.0.1" in captured.err
|
||||
or "error: build version should equal 0.0.2" in captured.err
|
||||
)
|
||||
|
||||
|
||||
def get_versions_from_constraint_file(constraint_file: Path) -> dict[str, str]:
|
||||
@@ -65,11 +89,15 @@ def test_pinned_versions(tmp_path, python_version, build_frontend_env_nouv):
|
||||
pytest.skip(f"Windows ARM64 does not support Python {python_version}")
|
||||
|
||||
project_dir = tmp_path / "project"
|
||||
project_with_expected_version_checks.generate(project_dir)
|
||||
test_projects.new_c_project().generate(project_dir)
|
||||
|
||||
# read the expected versions from the appropriate constraint file
|
||||
version_no_dot = python_version.replace(".", "")
|
||||
build_environment = {}
|
||||
build_pattern = f"[cp]p{version_no_dot}-*"
|
||||
|
||||
# create cross-platform Python before-build script to verify versions pre-build
|
||||
before_build_script = project_dir / "check_versions.py"
|
||||
before_build_script.write_text(CHECK_VERSIONS_SCRIPT)
|
||||
|
||||
if utils.get_platform() == "pyodide":
|
||||
constraint_filename = f"constraints-pyodide{version_no_dot}.txt"
|
||||
else:
|
||||
@@ -77,16 +105,13 @@ def test_pinned_versions(tmp_path, python_version, build_frontend_env_nouv):
|
||||
constraint_file = resources.PATH / constraint_filename
|
||||
constraint_versions = get_versions_from_constraint_file(constraint_file)
|
||||
|
||||
build_environment["EXPECTED_PIP_VERSION"] = constraint_versions["pip"]
|
||||
|
||||
cibw_environment_option = " ".join(f"{k}={v}" for k, v in build_environment.items())
|
||||
|
||||
# build and test the wheels
|
||||
# build and test the wheels (dependency version check occurs before-build)
|
||||
actual_wheels = utils.cibuildwheel_run(
|
||||
project_dir,
|
||||
add_env={
|
||||
"CIBW_BUILD": build_pattern,
|
||||
"CIBW_ENVIRONMENT": cibw_environment_option,
|
||||
"CIBW_BUILD": f"[cp]p{version_no_dot}-*",
|
||||
"CIBW_BEFORE_BUILD": f"python {before_build_script.name}",
|
||||
"EXPECTED_VERSIONS": json.dumps(constraint_versions),
|
||||
**build_frontend_env_nouv,
|
||||
},
|
||||
)
|
||||
@@ -107,10 +132,11 @@ def test_dependency_constraints(method, tmp_path, build_frontend_env_nouv):
|
||||
pytest.skip("linux doesn't pin individual tool versions, it pins manylinux images instead")
|
||||
|
||||
project_dir = tmp_path / "project"
|
||||
project_with_expected_version_checks.generate(project_dir)
|
||||
test_projects.new_c_project().generate(project_dir)
|
||||
|
||||
tool_versions = {
|
||||
"pip": "23.1.2",
|
||||
"build": "1.2.2",
|
||||
"delocate": "0.10.3",
|
||||
}
|
||||
|
||||
@@ -120,6 +146,7 @@ def test_dependency_constraints(method, tmp_path, build_frontend_env_nouv):
|
||||
textwrap.dedent(
|
||||
"""
|
||||
pip=={pip}
|
||||
build=={build}
|
||||
delocate=={delocate}
|
||||
""".format(**tool_versions)
|
||||
)
|
||||
@@ -133,7 +160,7 @@ def test_dependency_constraints(method, tmp_path, build_frontend_env_nouv):
|
||||
msg = f"Unknown method: {method}"
|
||||
raise ValueError(msg)
|
||||
|
||||
build_environment = {}
|
||||
skip = ""
|
||||
|
||||
if (
|
||||
utils.get_platform() == "windows"
|
||||
@@ -144,32 +171,29 @@ def test_dependency_constraints(method, tmp_path, build_frontend_env_nouv):
|
||||
# from a virtualenv seeded executable. See
|
||||
# https://github.com/oracle/graalpython/issues/491 and remove this once
|
||||
# GraalPy 24 is dropped
|
||||
build_frontend_env_nouv["CIBW_SKIP"] = "gp311*"
|
||||
skip = "gp311*"
|
||||
|
||||
for package_name, version in tool_versions.items():
|
||||
env_name = f"EXPECTED_{package_name.upper()}_VERSION"
|
||||
build_environment[env_name] = version
|
||||
# cross-platform Python script for dependency constraint checks
|
||||
before_build_script = project_dir / "check_versions.py"
|
||||
before_build_script.write_text(CHECK_VERSIONS_SCRIPT)
|
||||
|
||||
cibw_environment_option = " ".join(f"{k}={v}" for k, v in build_environment.items())
|
||||
|
||||
# build and test the wheels
|
||||
# build and test the wheels (dependency version check occurs pre-build)
|
||||
actual_wheels = utils.cibuildwheel_run(
|
||||
project_dir,
|
||||
add_env={
|
||||
"CIBW_ENVIRONMENT": cibw_environment_option,
|
||||
"CIBW_SKIP": skip,
|
||||
"CIBW_DEPENDENCY_VERSIONS": dependency_version_option,
|
||||
"CIBW_BEFORE_BUILD": f"python {before_build_script.name}",
|
||||
"EXPECTED_VERSIONS": json.dumps(tool_versions),
|
||||
**build_frontend_env_nouv,
|
||||
},
|
||||
single_python=True,
|
||||
)
|
||||
|
||||
# also check that we got the right wheels
|
||||
expected_wheels = utils.expected_wheels("spam", "0.1.0")
|
||||
expected_wheels = utils.expected_wheels("spam", "0.1.0", single_python=True)
|
||||
|
||||
if (
|
||||
utils.get_platform() == "windows"
|
||||
and method == "file"
|
||||
and build_frontend_env_nouv["CIBW_BUILD_FRONTEND"] == "build"
|
||||
):
|
||||
if skip == "gp*":
|
||||
# See reference to https://github.com/oracle/graalpython/issues/491
|
||||
# above
|
||||
expected_wheels = [w for w in expected_wheels if "graalpy311" not in w]
|
||||
|
||||
Reference in New Issue
Block a user