From c1b8a12cd5f0a6edf1201b6aacf15c025f000981 Mon Sep 17 00:00:00 2001 From: Matthieu Darbois Date: Mon, 17 Jun 2024 07:07:35 +0200 Subject: [PATCH] chore(tests): run a project with tests using `build[uv]` frontend (#1880) --- cibuildwheel/pyodide.py | 7 ++----- test/conftest.py | 18 +++++++++--------- test/test_before_test.py | 5 +++-- test/test_dependency_versions.py | 4 +++- test/test_pep518.py | 7 +++---- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/cibuildwheel/pyodide.py b/cibuildwheel/pyodide.py index d2ca04591..b62371203 100644 --- a/cibuildwheel/pyodide.py +++ b/cibuildwheel/pyodide.py @@ -22,6 +22,7 @@ BuildSelector, NonPlatformWheelError, call, + combine_constraints, download, ensure_node, extract_zip, @@ -285,11 +286,7 @@ def build(options: Options, tmp_path: Path) -> None: build_env = env.copy() if build_options.dependency_constraints: - our_constraints = str(constraints_path) - user_constraints = build_env.get("PIP_CONSTRAINT") - build_env["PIP_CONSTRAINT"] = " ".join( - c for c in [our_constraints, user_constraints] if c - ) + combine_constraints(build_env, constraints_path, identifier_tmp_dir) build_env["VIRTUALENV_PIP"] = pip_version call( "pyodide", diff --git a/test/conftest.py b/test/conftest.py index 3fbf1d67c..72329ec16 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -28,22 +28,22 @@ def pytest_addoption(parser) -> None: ) -@pytest.fixture( - params=[{"CIBW_BUILD_FRONTEND": "pip"}, {"CIBW_BUILD_FRONTEND": "build"}], ids=["pip", "build"] -) -def build_frontend_env_nouv(request) -> dict[str, str]: - if platform == "pyodide": +@pytest.fixture(params=["pip", "build"]) +def build_frontend_env_nouv(request: pytest.FixtureRequest) -> dict[str, str]: + frontend = request.param + if platform == "pyodide" and frontend == "pip": pytest.skip("Can't use pip as build frontend for pyodide platform") - return request.param # type: ignore[no-any-return] + return {"CIBW_BUILD_FRONTEND": frontend} @pytest.fixture() def build_frontend_env(build_frontend_env_nouv: dict[str, str]) -> dict[str, str]: - if build_frontend_env_nouv["CIBW_BUILD_FRONTEND"] == "build" and find_uv() is not None: - return {"CIBW_BUILD_FRONTEND": "build[uv]"} + frontend = build_frontend_env_nouv["CIBW_BUILD_FRONTEND"] + if frontend != "build" or platform == "pyodide" or find_uv() is None: + return build_frontend_env_nouv - return build_frontend_env_nouv + return {"CIBW_BUILD_FRONTEND": "build[uv]"} @pytest.fixture() diff --git a/test/test_before_test.py b/test/test_before_test.py index 08ef12def..59da3135f 100644 --- a/test/test_before_test.py +++ b/test/test_before_test.py @@ -34,7 +34,7 @@ def test_prefix(self): """ -def test(tmp_path): +def test(tmp_path, build_frontend_env): project_dir = tmp_path / "project" before_test_project.generate(project_dir) test_project_dir = project_dir / "dependency" @@ -49,7 +49,7 @@ def test(tmp_path): before_test_steps.extend( ["pyodide build {project}/dependency", "pip install --find-links dist/ spam"] ) - else: + elif build_frontend_env["CIBW_BUILD_FRONTEND"] in {"pip", "build"}: before_test_steps.append("python -m pip install {project}/dependency") before_test = " && ".join(before_test_steps) @@ -66,6 +66,7 @@ def test(tmp_path): # mac/linux. "CIBW_TEST_COMMAND": f"false || {utils.invoke_pytest()} {{project}}/test", "CIBW_TEST_COMMAND_WINDOWS": "pytest {project}/test", + **build_frontend_env, }, ) diff --git a/test/test_dependency_versions.py b/test/test_dependency_versions.py index defefc747..a7c573b25 100644 --- a/test/test_dependency_versions.py +++ b/test/test_dependency_versions.py @@ -52,12 +52,14 @@ def get_versions_from_constraint_file(constraint_file): return dict(re.findall(VERSION_REGEX, constraint_file_text)) -@pytest.mark.parametrize("python_version", ["3.6", "3.8", "3.10"]) +@pytest.mark.parametrize("python_version", ["3.6", "3.8", "3.12"]) def test_pinned_versions(tmp_path, python_version, build_frontend_env_nouv): 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") + if python_version != "3.12" and utils.platform == "pyodide": + pytest.skip(f"pyodide does not support Python {python_version}") project_dir = tmp_path / "project" project_with_expected_version_checks.generate(project_dir) diff --git a/test/test_pep518.py b/test/test_pep518.py index b9b132105..b1d99e8de 100644 --- a/test/test_pep518.py +++ b/test/test_pep518.py @@ -8,8 +8,8 @@ setup_py_add=textwrap.dedent( """ # Will fail if PEP 518 does work - import requests - assert requests.__version__ == "2.27.0", "Requests found but wrong version ({0})".format(requests.__version__) + import jmespath + assert jmespath.__version__ == "0.10.0", "'jmespath' found but wrong version ({0})".format(jmespath.__version__) # Just making sure environment is still set import os @@ -24,8 +24,7 @@ requires = [ "setuptools >= 42", "setuptools_scm[toml]>=4.1.2", - "wheel", - "requests==2.27.0" + "jmespath==0.10.0" ] build-backend = "setuptools.build_meta"