Skip to content

Commit

Permalink
fix: do not pre-seed setuptools / wheel in virtual environment (#1819)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeut committed May 11, 2024
1 parent 3ea0a6c commit cf18014
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 2 additions & 0 deletions cibuildwheel/resources/constraints-python36.txt
Expand Up @@ -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
19 changes: 14 additions & 5 deletions cibuildwheel/util.py
Expand Up @@ -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]:
"""
Expand All @@ -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])
Expand All @@ -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
Expand All @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions test/test_abi_variants.py
Expand Up @@ -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"""
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit cf18014

Please sign in to comment.