Skip to content

Commit 3b9c8d4

Browse files
authored
fix: don't seed setuptools/wheel in tests virtual environments. (#2329)
1 parent 462c995 commit 3b9c8d4

File tree

5 files changed

+22
-78
lines changed

5 files changed

+22
-78
lines changed

cibuildwheel/linux.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
from pathlib import Path, PurePath, PurePosixPath
99
from typing import assert_never
1010

11-
from packaging.version import Version
12-
1311
from . import errors
1412
from .architecture import Architecture
1513
from .frontend import BuildFrontendConfig, get_build_frontend_extra_flags
@@ -351,10 +349,7 @@ def build_in_container(
351349
container.call(["uv", "venv", venv_dir, "--python", python_bin / "python"], env=env)
352350
else:
353351
# Use embedded dependencies from virtualenv to ensure determinism
354-
venv_args = ["--no-periodic-update", "--pip=embed"]
355-
# In Python<3.12, setuptools & wheel are installed as well
356-
if Version(config.version) < Version("3.12"):
357-
venv_args.extend(("--setuptools=embed", "--wheel=embed"))
352+
venv_args = ["--no-periodic-update", "--pip=embed", "--no-setuptools", "--no-wheel"]
358353
container.call(["python", "-m", "virtualenv", *venv_args, venv_dir], env=env)
359354

360355
virtualenv_env = env.copy()

cibuildwheel/macos.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -643,10 +643,12 @@ def build(options: Options, tmp_path: Path) -> None:
643643
else:
644644
pip_install = functools.partial(call_with_arch, *pip, "install")
645645
# Use pip version from the initial env to ensure determinism
646-
venv_args = ["--no-periodic-update", f"--pip={pip_version}"]
647-
# In Python<3.12, setuptools & wheel are installed as well, use virtualenv embedded ones
648-
if Version(config.version) < Version("3.12"):
649-
venv_args.extend(("--setuptools=embed", "--wheel=embed"))
646+
venv_args = [
647+
"--no-periodic-update",
648+
f"--pip={pip_version}",
649+
"--no-setuptools",
650+
"--no-wheel",
651+
]
650652
call_with_arch("python", "-m", "virtualenv", *venv_args, venv_dir, env=env)
651653

652654
virtualenv_env = env.copy()

cibuildwheel/resources/constraints-python37.txt

Lines changed: 0 additions & 39 deletions
This file was deleted.

cibuildwheel/venv.py

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ def _ensure_virtualenv(version: str) -> Path:
3636
return path
3737

3838

39-
def _parse_constraints_for_virtualenv(
40-
seed_packages: list[str],
39+
def _parse_pip_constraint_for_virtualenv(
4140
dependency_constraint_flags: Sequence[PathOrStr],
42-
) -> dict[str, str]:
41+
) -> str:
4342
"""
4443
Parses the constraints file referenced by `dependency_constraint_flags` and returns a dict where
4544
the key is the package name, and the value is the constraint version.
@@ -50,8 +49,6 @@ def _parse_constraints_for_virtualenv(
5049
{macos|windows}.setup_python function.
5150
"""
5251
assert len(dependency_constraint_flags) in {0, 2}
53-
# only seed pip if other seed packages do not appear in a constraint file
54-
constraints_dict = {"pip": "embed"}
5552
if len(dependency_constraint_flags) == 2:
5653
assert dependency_constraint_flags[0] == "-c"
5754
constraint_path = Path(dependency_constraint_flags[1])
@@ -67,7 +64,7 @@ def _parse_constraints_for_virtualenv(
6764
requirement = Requirement(line)
6865
package = requirement.name
6966
if (
70-
package not in seed_packages
67+
package != "pip"
7168
or requirement.url is not None
7269
or requirement.marker is not None
7370
or len(requirement.extras) != 0
@@ -77,10 +74,10 @@ def _parse_constraints_for_virtualenv(
7774
specifier = next(iter(requirement.specifier))
7875
if specifier.operator != "==":
7976
continue
80-
constraints_dict[package] = specifier.version
77+
return specifier.version
8178
except InvalidRequirement:
8279
continue
83-
return constraints_dict
80+
return "embed"
8481

8582

8683
def virtualenv(
@@ -94,7 +91,7 @@ def virtualenv(
9491
"""
9592
Create a virtual environment. If `use_uv` is True,
9693
dependency_constraint_flags are ignored since nothing is installed in the
97-
venv. Otherwise, pip is installed, and setuptools + wheel if Python < 3.12.
94+
venv. Otherwise, pip is installed.
9895
"""
9996

10097
# virtualenv may fail if this is a symlink.
@@ -106,28 +103,16 @@ def virtualenv(
106103
call("uv", "venv", venv_path, "--python", python)
107104
else:
108105
virtualenv_app = _ensure_virtualenv(version)
109-
allowed_seed_packages = ["pip", "setuptools", "wheel"]
110-
constraints = _parse_constraints_for_virtualenv(
111-
allowed_seed_packages, dependency_constraint_flags
112-
)
113-
additional_flags: list[str] = []
114-
for package in allowed_seed_packages:
115-
if package in constraints:
116-
additional_flags.append(f"--{package}={constraints[package]}")
117-
else:
118-
additional_flags.append(f"--no-{package}")
106+
pip_constraint = _parse_pip_constraint_for_virtualenv(dependency_constraint_flags)
107+
additional_flags = [f"--pip={pip_constraint}", "--no-setuptools", "--no-wheel"]
119108

120109
# Using symlinks to pre-installed seed packages is really the fastest way to get a virtual
121110
# environment. The initial cost is a bit higher but reusing is much faster.
122111
# Windows does not always allow symlinks so just disabling for now.
123112
# Requires pip>=19.3 so disabling for "embed" because this means we don't know what's the
124113
# version of pip that will end-up installed.
125114
# c.f. https://virtualenv.pypa.io/en/latest/cli_interface.html#section-seeder
126-
if (
127-
not _IS_WIN
128-
and constraints["pip"] != "embed"
129-
and Version(constraints["pip"]) >= Version("19.3")
130-
):
115+
if not _IS_WIN and pip_constraint != "embed" and Version(pip_constraint) >= Version("19.3"):
131116
additional_flags.append("--symlink-app-data")
132117

133118
call(

cibuildwheel/windows.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from typing import assert_never
1111

1212
from filelock import FileLock
13-
from packaging.version import Version
1413

1514
from . import errors
1615
from .architecture import Architecture
@@ -497,10 +496,12 @@ def build(options: Options, tmp_path: Path) -> None:
497496
call("uv", "venv", venv_dir, f"--python={base_python}", env=env)
498497
else:
499498
# Use pip version from the initial env to ensure determinism
500-
venv_args = ["--no-periodic-update", f"--pip={pip_version}"]
501-
# In Python<3.12, setuptools & wheel are installed as well, use virtualenv embedded ones
502-
if Version(config.version) < Version("3.12"):
503-
venv_args.extend(("--setuptools=embed", "--wheel=embed"))
499+
venv_args = [
500+
"--no-periodic-update",
501+
f"--pip={pip_version}",
502+
"--no-setuptools",
503+
"--no-wheel",
504+
]
504505
call("python", "-m", "virtualenv", *venv_args, venv_dir, env=env)
505506

506507
virtualenv_env = env.copy()

0 commit comments

Comments
 (0)