Skip to content

Commit 93314a8

Browse files
authored
refactor: pull out dependency_constraint (#2347)
* refactor: pull out dependency_constraint Signed-off-by: Henry Schreiner <[email protected]> * refactor: address feedback Signed-off-by: Henry Schreiner <[email protected]> * ci: better parallel Signed-off-by: Henry Schreiner <[email protected]> --------- Signed-off-by: Henry Schreiner <[email protected]>
1 parent 8e2cc78 commit 93314a8

File tree

7 files changed

+65
-63
lines changed

7 files changed

+65
-63
lines changed

azure-pipelines.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pr:
77
jobs:
88
- job: linux_311
99
timeoutInMinutes: 120
10-
pool: {vmImage: 'Ubuntu-20.04'}
10+
pool: {vmImage: 'Ubuntu-22.04'}
1111
steps:
1212
- task: UsePythonVersion@0
1313
inputs:
@@ -27,7 +27,7 @@ jobs:
2727
- bash: |
2828
python -m pip install dependency-groups
2929
python -m dependency_groups test | xargs python -m pip install -e.
30-
python ./bin/run_tests.py --num-processes 2
30+
python ./bin/run_tests.py
3131
3232
- job: windows_311
3333
pool: {vmImage: 'windows-2019'}

bin/run_tests.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
from pathlib import Path
99

1010
if __name__ == "__main__":
11-
default_cpu_count = os.cpu_count() or 2
11+
if sys.version_info < (3, 13):
12+
default_cpu_count = os.cpu_count() or 2
13+
else:
14+
default_cpu_count = os.process_cpu_count() or 2
15+
1216
parser = argparse.ArgumentParser()
1317
parser.add_argument(
1418
"--run-podman", action="store_true", default=False, help="run podman tests (linux only)"

cibuildwheel/platforms/ios.py

+10-14
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from ..logger import log
2525
from ..options import Options
2626
from ..selector import BuildSelector
27-
from ..typing import PathOrStr
2827
from ..util import resources
2928
from ..util.cmd import call, shell
3029
from ..util.file import (
@@ -39,7 +38,7 @@
3938
find_compatible_wheel,
4039
get_pip_version,
4140
)
42-
from ..venv import virtualenv
41+
from ..venv import constraint_flags, virtualenv
4342
from .macos import install_cpython as install_build_cpython
4443

4544

@@ -151,7 +150,7 @@ def cross_virtualenv(
151150
multiarch: str,
152151
build_python: Path,
153152
venv_path: Path,
154-
dependency_constraint_flags: Sequence[PathOrStr],
153+
dependency_constraint: Path | None,
155154
xbuild_tools: Sequence[str] | None,
156155
) -> dict[str, str]:
157156
"""Create a cross-compilation virtual environment.
@@ -178,8 +177,8 @@ def cross_virtualenv(
178177
:param build_python: The path to the python binary for the build platform
179178
:param venv_path: The path where the cross virtual environment should be
180179
created.
181-
:param dependency_constraint_flags: Any flags that should be used when
182-
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.
183182
:param xbuild_tools: A list of executable names (without paths) that are
184183
on the path, but must be preserved in the cross environment.
185184
"""
@@ -188,7 +187,7 @@ def cross_virtualenv(
188187
py_version,
189188
build_python,
190189
venv_path,
191-
dependency_constraint_flags,
190+
dependency_constraint,
192191
use_uv=False,
193192
)
194193

@@ -279,7 +278,7 @@ def setup_python(
279278
tmp: Path,
280279
*,
281280
python_configuration: PythonConfiguration,
282-
dependency_constraint_flags: Sequence[PathOrStr],
281+
dependency_constraint: Path | None,
283282
environment: ParsedEnvironment,
284283
build_frontend: BuildFrontendName,
285284
xbuild_tools: Sequence[str] | None,
@@ -334,7 +333,7 @@ def setup_python(
334333
multiarch=python_configuration.multiarch,
335334
build_python=build_python,
336335
venv_path=venv_path,
337-
dependency_constraint_flags=dependency_constraint_flags,
336+
dependency_constraint=dependency_constraint,
338337
xbuild_tools=xbuild_tools,
339338
)
340339
venv_bin_path = venv_path / "bin"
@@ -351,7 +350,7 @@ def setup_python(
351350
"install",
352351
"--upgrade",
353352
"pip",
354-
*dependency_constraint_flags,
353+
*constraint_flags(dependency_constraint),
355354
env=env,
356355
cwd=venv_path,
357356
)
@@ -397,7 +396,7 @@ def setup_python(
397396
"install",
398397
"--upgrade",
399398
"build[virtualenv]",
400-
*dependency_constraint_flags,
399+
*constraint_flags(dependency_constraint),
401400
env=env,
402401
)
403402
else:
@@ -453,14 +452,11 @@ def build(options: Options, tmp_path: Path) -> None:
453452
constraints_path = build_options.dependency_constraints.get_for_python_version(
454453
version=config.version, tmp_dir=identifier_tmp_dir
455454
)
456-
dependency_constraint_flags: Sequence[PathOrStr] = (
457-
["-c", constraints_path] if constraints_path else []
458-
)
459455

460456
target_install_path, env = setup_python(
461457
identifier_tmp_dir / "build",
462458
python_configuration=config,
463-
dependency_constraint_flags=dependency_constraint_flags,
459+
dependency_constraint=constraints_path,
464460
environment=build_options.environment,
465461
build_frontend=build_frontend.name,
466462
xbuild_tools=build_options.xbuild_tools,

cibuildwheel/platforms/macos.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import subprocess
88
import sys
99
import typing
10-
from collections.abc import Sequence, Set
10+
from collections.abc import Set
1111
from dataclasses import dataclass
1212
from pathlib import Path
1313
from typing import Literal, assert_never
@@ -23,7 +23,6 @@
2323
from ..logger import log
2424
from ..options import Options
2525
from ..selector import BuildSelector
26-
from ..typing import PathOrStr
2726
from ..util import resources
2827
from ..util.cmd import call, shell
2928
from ..util.file import (
@@ -34,7 +33,7 @@
3433
)
3534
from ..util.helpers import prepare_command, unwrap
3635
from ..util.packaging import combine_constraints, find_compatible_wheel, get_pip_version
37-
from ..venv import find_uv, virtualenv
36+
from ..venv import constraint_flags, find_uv, virtualenv
3837

3938

4039
@functools.cache
@@ -195,7 +194,7 @@ def install_pypy(tmp: Path, url: str) -> Path:
195194
def setup_python(
196195
tmp: Path,
197196
python_configuration: PythonConfiguration,
198-
dependency_constraint_flags: Sequence[PathOrStr],
197+
dependency_constraint: Path | None,
199198
environment: ParsedEnvironment,
200199
build_frontend: BuildFrontendName,
201200
) -> tuple[Path, dict[str, str]]:
@@ -226,7 +225,7 @@ def setup_python(
226225
python_configuration.version,
227226
base_python,
228227
venv_path,
229-
dependency_constraint_flags,
228+
dependency_constraint,
230229
use_uv=use_uv,
231230
)
232231
venv_bin_path = venv_path / "bin"
@@ -256,7 +255,7 @@ def setup_python(
256255
"install",
257256
"--upgrade",
258257
"pip",
259-
*dependency_constraint_flags,
258+
*constraint_flags(dependency_constraint),
260259
env=env,
261260
cwd=venv_path,
262261
)
@@ -351,7 +350,7 @@ def setup_python(
351350
"install",
352351
"--upgrade",
353352
"delocate",
354-
*dependency_constraint_flags,
353+
*constraint_flags(dependency_constraint),
355354
env=env,
356355
)
357356
elif build_frontend == "build":
@@ -361,7 +360,7 @@ def setup_python(
361360
"--upgrade",
362361
"delocate",
363362
"build[virtualenv]",
364-
*dependency_constraint_flags,
363+
*constraint_flags(dependency_constraint),
365364
env=env,
366365
)
367366
elif build_frontend == "build[uv]":
@@ -373,7 +372,7 @@ def setup_python(
373372
"--upgrade",
374373
"delocate",
375374
"build[virtualenv, uv]",
376-
*dependency_constraint_flags,
375+
*constraint_flags(dependency_constraint),
377376
env=env,
378377
)
379378
else:
@@ -427,14 +426,11 @@ def build(options: Options, tmp_path: Path) -> None:
427426
constraints_path = build_options.dependency_constraints.get_for_python_version(
428427
version=config.version, tmp_dir=identifier_tmp_dir
429428
)
430-
dependency_constraint_flags: Sequence[PathOrStr] = (
431-
["-c", constraints_path] if constraints_path else []
432-
)
433429

434430
base_python, env = setup_python(
435431
identifier_tmp_dir / "build",
436432
config,
437-
dependency_constraint_flags,
433+
constraints_path,
438434
build_options.environment,
439435
build_frontend.name,
440436
)
@@ -621,7 +617,13 @@ def build(options: Options, tmp_path: Path) -> None:
621617
# set up a virtual environment to install and test from, to make sure
622618
# there are no dependencies that were pulled in at build time.
623619
if not use_uv:
624-
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+
)
625627

626628
venv_dir = identifier_tmp_dir / f"venv-test-{testing_arch}"
627629

cibuildwheel/platforms/pyodide.py

+7-11
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,14 +144,14 @@ 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)
152151

153152
log.step("Setting up build environment...")
154153
venv_path = tmp / "venv"
155-
env = virtualenv(python_configuration.version, base_python, venv_path, [], use_uv=False)
154+
env = virtualenv(python_configuration.version, base_python, venv_path, None, use_uv=False)
156155
venv_bin_path = venv_path / "bin"
157156
assert venv_bin_path.exists()
158157
env["PIP_DISABLE_PIP_VERSION_CHECK"] = "1"
@@ -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: Sequence[PathOrStr] = (
273-
["-c", constraints_path] 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)

0 commit comments

Comments
 (0)