Skip to content

Commit cf18014

Browse files
authored
fix: do not pre-seed setuptools / wheel in virtual environment (#1819)
1 parent 3ea0a6c commit cf18014

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

cibuildwheel/resources/constraints-python36.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@ zipp==3.6.0
4848
# The following packages are considered to be unsafe in a requirements file:
4949
pip==21.3.1
5050
# via -r cibuildwheel/resources/constraints.in
51+
setuptools==59.6.0
52+
# via -r cibuildwheel/resources/constraints.in

cibuildwheel/util.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ def _ensure_virtualenv() -> Path:
540540

541541

542542
def _parse_constraints_for_virtualenv(
543+
seed_packages: list[str],
543544
dependency_constraint_flags: Sequence[PathOrStr],
544545
) -> dict[str, str]:
545546
"""
@@ -552,8 +553,8 @@ def _parse_constraints_for_virtualenv(
552553
{macos|windows}.setup_python function.
553554
"""
554555
assert len(dependency_constraint_flags) in {0, 2}
555-
packages = ["pip", "setuptools", "wheel"]
556-
constraints_dict = {package: "embed" for package in packages}
556+
# only seed pip if other seed packages do not appear in a constraint file
557+
constraints_dict = {"pip": "embed"}
557558
if len(dependency_constraint_flags) == 2:
558559
assert dependency_constraint_flags[0] == "-c"
559560
constraint_path = Path(dependency_constraint_flags[1])
@@ -569,7 +570,7 @@ def _parse_constraints_for_virtualenv(
569570
requirement = Requirement(line)
570571
package = requirement.name
571572
if (
572-
package not in packages
573+
package not in seed_packages
573574
or requirement.url is not None
574575
or requirement.marker is not None
575576
or len(requirement.extras) != 0
@@ -590,8 +591,16 @@ def virtualenv(
590591
) -> dict[str, str]:
591592
assert python.exists()
592593
virtualenv_app = _ensure_virtualenv()
593-
constraints = _parse_constraints_for_virtualenv(dependency_constraint_flags)
594-
additional_flags = [f"--{package}={version}" for package, version in constraints.items()]
594+
allowed_seed_packages = ["pip", "setuptools", "wheel"]
595+
constraints = _parse_constraints_for_virtualenv(
596+
allowed_seed_packages, dependency_constraint_flags
597+
)
598+
additional_flags: list[str] = []
599+
for package in allowed_seed_packages:
600+
if package in constraints:
601+
additional_flags.append(f"--{package}={constraints[package]}")
602+
else:
603+
additional_flags.append(f"--no-{package}")
595604

596605
# Using symlinks to pre-installed seed packages is really the fastest way to get a virtual
597606
# environment. The initial cost is a bit higher but reusing is much faster.

test/test_abi_variants.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
from . import test_projects, utils
66

7+
pyproject_toml = r"""
8+
[build-system]
9+
requires = ["setuptools", "wheel"]
10+
build-backend = "setuptools.build_meta"
11+
"""
12+
713
limited_api_project = test_projects.new_c_project(
814
setup_py_add=textwrap.dedent(
915
r"""
@@ -30,6 +36,8 @@ def get_tag(self):
3036
setup_py_setup_args_add="cmdclass=cmdclass",
3137
)
3238

39+
limited_api_project.files["pyproject.toml"] = pyproject_toml
40+
3341

3442
def test_abi3(tmp_path):
3543
project_dir = tmp_path / "project"
@@ -155,6 +163,8 @@ def test():
155163
"""
156164
)
157165

166+
ctypes_project.files["pyproject.toml"] = pyproject_toml
167+
158168

159169
def test_abi_none(tmp_path, capfd):
160170
project_dir = tmp_path / "project"

0 commit comments

Comments
 (0)