From cf18014fce969628c72a266396f72ef672e9a8d4 Mon Sep 17 00:00:00 2001 From: Matthieu Darbois Date: Sat, 11 May 2024 22:24:01 +0200 Subject: [PATCH] fix: do not pre-seed setuptools / wheel in virtual environment (#1819) --- .../resources/constraints-python36.txt | 2 ++ cibuildwheel/util.py | 19 ++++++++++++++----- test/test_abi_variants.py | 10 ++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/cibuildwheel/resources/constraints-python36.txt b/cibuildwheel/resources/constraints-python36.txt index ff4e8609d..409e75c10 100644 --- a/cibuildwheel/resources/constraints-python36.txt +++ b/cibuildwheel/resources/constraints-python36.txt @@ -48,3 +48,5 @@ zipp==3.6.0 # The following packages are considered to be unsafe in a requirements file: pip==21.3.1 # via -r cibuildwheel/resources/constraints.in +setuptools==59.6.0 + # via -r cibuildwheel/resources/constraints.in diff --git a/cibuildwheel/util.py b/cibuildwheel/util.py index fb334257f..a225575b8 100644 --- a/cibuildwheel/util.py +++ b/cibuildwheel/util.py @@ -540,6 +540,7 @@ def _ensure_virtualenv() -> Path: def _parse_constraints_for_virtualenv( + seed_packages: list[str], dependency_constraint_flags: Sequence[PathOrStr], ) -> dict[str, str]: """ @@ -552,8 +553,8 @@ def _parse_constraints_for_virtualenv( {macos|windows}.setup_python function. """ assert len(dependency_constraint_flags) in {0, 2} - packages = ["pip", "setuptools", "wheel"] - constraints_dict = {package: "embed" for package in packages} + # only seed pip if other seed packages do not appear in a constraint file + constraints_dict = {"pip": "embed"} if len(dependency_constraint_flags) == 2: assert dependency_constraint_flags[0] == "-c" constraint_path = Path(dependency_constraint_flags[1]) @@ -569,7 +570,7 @@ def _parse_constraints_for_virtualenv( requirement = Requirement(line) package = requirement.name if ( - package not in packages + package not in seed_packages or requirement.url is not None or requirement.marker is not None or len(requirement.extras) != 0 @@ -590,8 +591,16 @@ def virtualenv( ) -> dict[str, str]: assert python.exists() virtualenv_app = _ensure_virtualenv() - constraints = _parse_constraints_for_virtualenv(dependency_constraint_flags) - additional_flags = [f"--{package}={version}" for package, version in constraints.items()] + allowed_seed_packages = ["pip", "setuptools", "wheel"] + constraints = _parse_constraints_for_virtualenv( + allowed_seed_packages, dependency_constraint_flags + ) + additional_flags: list[str] = [] + for package in allowed_seed_packages: + if package in constraints: + additional_flags.append(f"--{package}={constraints[package]}") + else: + additional_flags.append(f"--no-{package}") # Using symlinks to pre-installed seed packages is really the fastest way to get a virtual # environment. The initial cost is a bit higher but reusing is much faster. diff --git a/test/test_abi_variants.py b/test/test_abi_variants.py index 131b1ee9f..d203c06fe 100644 --- a/test/test_abi_variants.py +++ b/test/test_abi_variants.py @@ -4,6 +4,12 @@ from . import test_projects, utils +pyproject_toml = r""" +[build-system] +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" +""" + limited_api_project = test_projects.new_c_project( setup_py_add=textwrap.dedent( r""" @@ -30,6 +36,8 @@ def get_tag(self): setup_py_setup_args_add="cmdclass=cmdclass", ) +limited_api_project.files["pyproject.toml"] = pyproject_toml + def test_abi3(tmp_path): project_dir = tmp_path / "project" @@ -155,6 +163,8 @@ def test(): """ ) +ctypes_project.files["pyproject.toml"] = pyproject_toml + def test_abi_none(tmp_path, capfd): project_dir = tmp_path / "project"