From 2a59a2c6ad90a772379a097361246e3bb549230e Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Wed, 21 Oct 2026 11:24:40 -0400 Subject: [PATCH 1/2] fix: seed build's isolated env with the pinned pip build's virtualenv backend seeded its own bundled pip, ignoring the dependency constraints. On GraalPy 25.0, pip 26.2 (urllib3 2.7) cannot create an SSLContext, so builds failed even though pip is pinned for GraalPy. Set VIRTUALENV_PIP to the build venv's pip on macOS and Windows. Fixes #2984. Assisted-by: ClaudeCode:claude-opus-5-5 --- cibuildwheel/platforms/macos.py | 3 +++ cibuildwheel/platforms/windows.py | 6 ++++- test/test_dependency_versions.py | 37 +++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/cibuildwheel/platforms/macos.py b/cibuildwheel/platforms/macos.py index 21d48e10d..3334dfe98 100644 --- a/cibuildwheel/platforms/macos.py +++ b/cibuildwheel/platforms/macos.py @@ -567,6 +567,9 @@ def build(options: Options, tmp_path: Path) -> None: and "-n" not in extra_flags ): extra_flags.append("--installer=uv") + if pip_version is not None: + # build's isolated virtualenv seeds its own bundled pip otherwise, see #2984 + build_env.setdefault("VIRTUALENV_PIP", pip_version) call( "python", "-m", diff --git a/cibuildwheel/platforms/windows.py b/cibuildwheel/platforms/windows.py index 364cae3af..418e80bcc 100644 --- a/cibuildwheel/platforms/windows.py +++ b/cibuildwheel/platforms/windows.py @@ -518,6 +518,10 @@ def build(options: Options, tmp_path: Path) -> None: and "-n" not in extra_flags ): extra_flags.append("--installer=uv") + build_env = env.copy() + if pip_version is not None: + # build's isolated virtualenv seeds its own bundled pip otherwise, see #2984 + build_env.setdefault("VIRTUALENV_PIP", pip_version) call( "python", @@ -527,7 +531,7 @@ def build(options: Options, tmp_path: Path) -> None: "--wheel", f"--outdir={built_wheel_dir}", *extra_flags, - env=env, + env=build_env, ) case "uv": assert uv_path is not None diff --git a/test/test_dependency_versions.py b/test/test_dependency_versions.py index 3c1004d26..0d856855b 100644 --- a/test/test_dependency_versions.py +++ b/test/test_dependency_versions.py @@ -199,3 +199,40 @@ def test_dependency_constraints( expected_wheels = utils.expected_wheels("spam", "0.1.0", single_python=True) assert set(actual_wheels) == set(expected_wheels) + + +project_with_isolated_pip_check = test_projects.new_c_project( + setup_py_add=textwrap.dedent( + """ + from importlib.metadata import version + + with open("outer_pip_version.txt") as f: + outer_pip_version = f.read().strip() + assert version("pip") == outer_pip_version, (version("pip"), outer_pip_version) + """ + ) +) + + +def test_build_isolated_env_pip_version(tmp_path: Path) -> None: + # build's isolated virtualenv seeds the same pip as the build venv, see #2984 + if utils.get_platform() not in {"macos", "windows"}: + pytest.skip("only macOS and Windows use the build frontend's virtualenv backend") + + project_dir = tmp_path / "project" + project_with_isolated_pip_check.generate(project_dir) + + add_env = { + "CIBW_BUILD_FRONTEND": "build", + "CIBW_BEFORE_BUILD": ( + 'python -c "import importlib.metadata as m, pathlib;' + " pathlib.Path('outer_pip_version.txt').write_text(m.version('pip'))\"" + ), + # differs from the pip bundled with virtualenv + "CIBW_DEPENDENCY_VERSIONS": "packages: pip==25.3", + } + + actual_wheels = utils.cibuildwheel_run(project_dir, add_env=add_env, single_python=True) + + expected_wheels = utils.expected_wheels("spam", "0.1.0", single_python=True) + assert set(actual_wheels) == set(expected_wheels) From 4c68fa28f1734900b560b25b7fd1260da831ba80 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Wed, 21 Oct 2026 12:13:27 -0400 Subject: [PATCH 2/2] test: accept build's venv backend in isolated pip test On Windows, build uses the outer pip, so the isolated env has no pip. Assisted-by: ClaudeCode:claude-opus-5-5 --- test/test_dependency_versions.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/test_dependency_versions.py b/test/test_dependency_versions.py index 0d856855b..3a18b4ef3 100644 --- a/test/test_dependency_versions.py +++ b/test/test_dependency_versions.py @@ -204,11 +204,16 @@ def test_dependency_constraints( project_with_isolated_pip_check = test_projects.new_c_project( setup_py_add=textwrap.dedent( """ - from importlib.metadata import version + from importlib.metadata import PackageNotFoundError, version with open("outer_pip_version.txt") as f: outer_pip_version = f.read().strip() - assert version("pip") == outer_pip_version, (version("pip"), outer_pip_version) + try: + isolated_pip_version = version("pip") + except PackageNotFoundError: + # venv backend: build installs with the outer pip + isolated_pip_version = outer_pip_version + assert isolated_pip_version == outer_pip_version, (isolated_pip_version, outer_pip_version) """ ) ) @@ -217,7 +222,7 @@ def test_dependency_constraints( def test_build_isolated_env_pip_version(tmp_path: Path) -> None: # build's isolated virtualenv seeds the same pip as the build venv, see #2984 if utils.get_platform() not in {"macos", "windows"}: - pytest.skip("only macOS and Windows use the build frontend's virtualenv backend") + pytest.skip("only macOS and Windows can use the build frontend's virtualenv backend") project_dir = tmp_path / "project" project_with_isolated_pip_check.generate(project_dir)