Skip to content

Commit d633518

Browse files
committed
refactor: address feedback
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 803ccbd commit d633518

File tree

4 files changed

+27
-33
lines changed

4 files changed

+27
-33
lines changed

Diff for: cibuildwheel/platforms/ios.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ def cross_virtualenv(
177177
:param build_python: The path to the python binary for the build platform
178178
:param venv_path: The path where the cross virtual environment should be
179179
created.
180-
:param dependency_constraint_flags: Any flags that should be used when
181-
constraining dependencies in the environment.
180+
:param dependency_constraint: A path to a constraint file that should be
181+
used when constraining dependencies in the environment.
182182
:param xbuild_tools: A list of executable names (without paths) that are
183183
on the path, but must be preserved in the cross environment.
184184
"""
@@ -326,8 +326,6 @@ def setup_python(
326326

327327
log.step("Creating cross build environment...")
328328

329-
dependency_constraint_flags = constraint_flags(dependency_constraint)
330-
331329
venv_path = tmp / "venv"
332330
env = cross_virtualenv(
333331
py_version=python_configuration.version,
@@ -352,7 +350,7 @@ def setup_python(
352350
"install",
353351
"--upgrade",
354352
"pip",
355-
*dependency_constraint_flags,
353+
*constraint_flags(dependency_constraint),
356354
env=env,
357355
cwd=venv_path,
358356
)
@@ -398,7 +396,7 @@ def setup_python(
398396
"install",
399397
"--upgrade",
400398
"build[virtualenv]",
401-
*dependency_constraint_flags,
399+
*constraint_flags(dependency_constraint),
402400
env=env,
403401
)
404402
else:

Diff for: cibuildwheel/platforms/macos.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,6 @@ def setup_python(
219219
f"{base_python.name} not found, has {list(base_python.parent.iterdir())}"
220220
)
221221

222-
dependency_constraint_flags = constraint_flags(dependency_constraint)
223-
224222
log.step("Setting up build environment...")
225223
venv_path = tmp / "venv"
226224
env = virtualenv(
@@ -257,7 +255,7 @@ def setup_python(
257255
"install",
258256
"--upgrade",
259257
"pip",
260-
*dependency_constraint_flags,
258+
*constraint_flags(dependency_constraint),
261259
env=env,
262260
cwd=venv_path,
263261
)
@@ -352,7 +350,7 @@ def setup_python(
352350
"install",
353351
"--upgrade",
354352
"delocate",
355-
*dependency_constraint_flags,
353+
*constraint_flags(dependency_constraint),
356354
env=env,
357355
)
358356
elif build_frontend == "build":
@@ -362,7 +360,7 @@ def setup_python(
362360
"--upgrade",
363361
"delocate",
364362
"build[virtualenv]",
365-
*dependency_constraint_flags,
363+
*constraint_flags(dependency_constraint),
366364
env=env,
367365
)
368366
elif build_frontend == "build[uv]":
@@ -374,7 +372,7 @@ def setup_python(
374372
"--upgrade",
375373
"delocate",
376374
"build[virtualenv, uv]",
377-
*dependency_constraint_flags,
375+
*constraint_flags(dependency_constraint),
378376
env=env,
379377
)
380378
else:
@@ -428,7 +426,6 @@ def build(options: Options, tmp_path: Path) -> None:
428426
constraints_path = build_options.dependency_constraints.get_for_python_version(
429427
version=config.version, tmp_dir=identifier_tmp_dir
430428
)
431-
dependency_constraint_flags = constraint_flags(constraints_path)
432429

433430
base_python, env = setup_python(
434431
identifier_tmp_dir / "build",
@@ -620,7 +617,13 @@ def build(options: Options, tmp_path: Path) -> None:
620617
# set up a virtual environment to install and test from, to make sure
621618
# there are no dependencies that were pulled in at build time.
622619
if not use_uv:
623-
call("pip", "install", "virtualenv", *dependency_constraint_flags, env=env)
620+
call(
621+
"pip",
622+
"install",
623+
"virtualenv",
624+
*constraint_flags(constraints_path),
625+
env=env,
626+
)
624627

625628
venv_dir = identifier_tmp_dir / f"venv-test-{testing_arch}"
626629

Diff for: cibuildwheel/platforms/pyodide.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import shutil
44
import sys
55
import tomllib
6-
from collections.abc import Sequence, Set
6+
from collections.abc import Set
77
from dataclasses import dataclass
88
from pathlib import Path
99
from tempfile import TemporaryDirectory
@@ -18,7 +18,6 @@
1818
from ..logger import log
1919
from ..options import Options
2020
from ..selector import BuildSelector
21-
from ..typing import PathOrStr
2221
from ..util import resources
2322
from ..util.cmd import call, shell
2423
from ..util.file import (
@@ -31,7 +30,7 @@
3130
)
3231
from ..util.helpers import prepare_command
3332
from ..util.packaging import combine_constraints, find_compatible_wheel, get_pip_version
34-
from ..venv import virtualenv
33+
from ..venv import constraint_flags, virtualenv
3534

3635
IS_WIN: Final[bool] = sys.platform.startswith("win")
3736

@@ -145,7 +144,7 @@ def get_base_python(identifier: str) -> Path:
145144
def setup_python(
146145
tmp: Path,
147146
python_configuration: PythonConfiguration,
148-
dependency_constraint_flags: Sequence[PathOrStr],
147+
constraints_path: Path | None,
149148
environment: ParsedEnvironment,
150149
) -> dict[str, str]:
151150
base_python = get_base_python(python_configuration.identifier)
@@ -166,7 +165,7 @@ def setup_python(
166165
"install",
167166
"--upgrade",
168167
"pip",
169-
*dependency_constraint_flags,
168+
*constraint_flags(constraints_path),
170169
env=env,
171170
cwd=venv_path,
172171
)
@@ -198,7 +197,7 @@ def setup_python(
198197
"auditwheel-emscripten",
199198
"build[virtualenv]",
200199
"pyodide-build",
201-
*dependency_constraint_flags,
200+
*constraint_flags(constraints_path),
202201
env=env,
203202
)
204203

@@ -269,14 +268,11 @@ def build(options: Options, tmp_path: Path) -> None:
269268
constraints_path = build_options.dependency_constraints.get_for_python_version(
270269
version=config.version, variant="pyodide", tmp_dir=identifier_tmp_dir
271270
)
272-
dependency_constraint_flags = (
273-
["-c", constraints_path.as_uri()] if constraints_path else []
274-
)
275271

276272
env = setup_python(
277273
identifier_tmp_dir / "build",
278274
config,
279-
dependency_constraint_flags,
275+
constraints_path,
280276
build_options.environment,
281277
)
282278
pip_version = get_pip_version(env)

Diff for: cibuildwheel/platforms/windows.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def setup_python(
247247
if build_frontend == "build[uv]" and not can_use_uv(python_configuration):
248248
build_frontend = "build"
249249

250-
use_uv = build_frontend in {"build[uv]", "uv"}
250+
use_uv = build_frontend == "build[uv]"
251251
uv_path = find_uv()
252252

253253
log.step("Setting up build environment...")
@@ -260,8 +260,6 @@ def setup_python(
260260
use_uv=use_uv,
261261
)
262262

263-
dependency_constraint_flags = constraint_flags(dependency_constraint)
264-
265263
# set up environment variables for run_with_env
266264
env["PYTHON_VERSION"] = python_configuration.version
267265
env["PYTHON_ARCH"] = python_configuration.arch
@@ -311,7 +309,7 @@ def setup_python(
311309
"install",
312310
"--upgrade",
313311
"build[virtualenv]",
314-
*dependency_constraint_flags,
312+
*constraint_flags(dependency_constraint),
315313
env=env,
316314
)
317315
elif build_frontend == "build[uv]":
@@ -322,7 +320,7 @@ def setup_python(
322320
"install",
323321
"--upgrade",
324322
"build[virtualenv]",
325-
*dependency_constraint_flags,
323+
*constraint_flags(dependency_constraint),
326324
env=env,
327325
)
328326

@@ -371,9 +369,6 @@ def build(options: Options, tmp_path: Path) -> None:
371369
version=config.version,
372370
tmp_dir=identifier_tmp_dir,
373371
)
374-
dependency_constraint_flags = (
375-
["-c", constraints_path.as_uri()] if constraints_path else []
376-
)
377372

378373
# install Python
379374
base_python, env = setup_python(
@@ -492,7 +487,9 @@ def build(options: Options, tmp_path: Path) -> None:
492487
# set up a virtual environment to install and test from, to make sure
493488
# there are no dependencies that were pulled in at build time.
494489
if not use_uv:
495-
call("pip", "install", "virtualenv", *dependency_constraint_flags, env=env)
490+
call(
491+
"pip", "install", "virtualenv", *constraint_flags(constraints_path), env=env
492+
)
496493

497494
venv_dir = identifier_tmp_dir / "venv-test"
498495

0 commit comments

Comments
 (0)