Skip to content

Commit bcedd46

Browse files
committed
feat: option to build directly with uv
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 93314a8 commit bcedd46

File tree

7 files changed

+61
-11
lines changed

7 files changed

+61
-11
lines changed

bin/generate_schema.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,23 @@
5454
type: string_array
5555
build-frontend:
5656
default: default
57-
description: Set the tool to use to build, either "pip" (default for now), "build", or "build[uv]"
57+
description: Set the tool to use to build, either "pip" (default for now), "build", "build[uv]", or "uv".
5858
oneOf:
59-
- enum: [pip, build, "build[uv]", default]
59+
- enum: [pip, build, "build[uv]", uv, default]
6060
- type: string
6161
pattern: '^pip; ?args:'
6262
- type: string
6363
pattern: '^build; ?args:'
6464
- type: string
6565
pattern: '^build\\[uv\\]; ?args:'
66+
- type: string
67+
pattern: '^uv; ?args:'
6668
- type: object
6769
additionalProperties: false
6870
required: [name]
6971
properties:
7072
name:
71-
enum: [pip, build, "build[uv]"]
73+
enum: [pip, build, "build[uv]", uv]
7274
args:
7375
type: array
7476
items:

cibuildwheel/frontend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .logger import log
88
from .util.helpers import parse_key_value_string
99

10-
BuildFrontendName = Literal["pip", "build", "build[uv]"]
10+
BuildFrontendName = Literal["pip", "build", "build[uv]", "uv"]
1111

1212

1313
@dataclass(frozen=True)

cibuildwheel/platforms/ios.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def setup_python(
283283
build_frontend: BuildFrontendName,
284284
xbuild_tools: Sequence[str] | None,
285285
) -> tuple[Path, dict[str, str]]:
286-
if build_frontend == "build[uv]":
286+
if build_frontend == "build[uv]" or build_frontend == "uv":
287287
msg = "uv doesn't support iOS"
288288
raise errors.FatalError(msg)
289289

@@ -439,7 +439,7 @@ def build(options: Options, tmp_path: Path) -> None:
439439
build_options = options.build_options(config.identifier)
440440
build_frontend = build_options.build_frontend or BuildFrontendConfig("build")
441441
# uv doesn't support iOS
442-
if build_frontend.name == "build[uv]":
442+
if build_frontend.name == "build[uv]" or build_frontend.name == "uv":
443443
msg = "uv doesn't support iOS"
444444
raise errors.FatalError(msg)
445445

cibuildwheel/platforms/linux.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def build_in_container(
204204
local_identifier_tmp_dir = local_tmp_dir / config.identifier
205205
build_options = options.build_options(config.identifier)
206206
build_frontend = build_options.build_frontend or BuildFrontendConfig("build")
207-
use_uv = build_frontend.name == "build[uv]"
207+
use_uv = build_frontend.name in {"build[uv]", "uv"}
208208
pip = ["uv", "pip"] if use_uv else ["pip"]
209209

210210
log.step("Setting up build environment...")
@@ -303,6 +303,18 @@ def build_in_container(
303303
],
304304
env=env,
305305
)
306+
elif build_frontend.name == "uv":
307+
container.call(
308+
[
309+
"uv",
310+
"build",
311+
container_package_dir,
312+
"--wheel",
313+
f"--out-dir={built_wheel_dir}",
314+
*extra_flags,
315+
],
316+
env=env,
317+
)
306318
else:
307319
assert_never(build_frontend)
308320

cibuildwheel/platforms/macos.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def setup_python(
199199
build_frontend: BuildFrontendName,
200200
) -> tuple[Path, dict[str, str]]:
201201
uv_path = find_uv()
202-
use_uv = build_frontend == "build[uv]"
202+
use_uv = build_frontend in {"build[uv]", "uv"}
203203

204204
tmp.mkdir()
205205
implementation_id = python_configuration.identifier.split("-")[0]
@@ -375,6 +375,17 @@ def setup_python(
375375
*constraint_flags(dependency_constraint),
376376
env=env,
377377
)
378+
elif build_frontend == "uv":
379+
assert uv_path is not None
380+
call(
381+
uv_path,
382+
"pip",
383+
"install",
384+
"--upgrade",
385+
"delocate",
386+
*constraint_flags(dependency_constraint),
387+
env=env,
388+
)
378389
else:
379390
assert_never(build_frontend)
380391

@@ -407,7 +418,7 @@ def build(options: Options, tmp_path: Path) -> None:
407418
for config in python_configurations:
408419
build_options = options.build_options(config.identifier)
409420
build_frontend = build_options.build_frontend or BuildFrontendConfig("build")
410-
use_uv = build_frontend.name == "build[uv]"
421+
use_uv = build_frontend.name in {"build[uv]", "uv"}
411422
uv_path = find_uv()
412423
if use_uv and uv_path is None:
413424
msg = "uv not found"
@@ -494,6 +505,16 @@ def build(options: Options, tmp_path: Path) -> None:
494505
*extra_flags,
495506
env=build_env,
496507
)
508+
elif build_frontend.name == "uv":
509+
call(
510+
"uv",
511+
"build",
512+
build_options.package_dir,
513+
"--wheel",
514+
f"--out-dir={built_wheel_dir}",
515+
*extra_flags,
516+
env=build_env,
517+
)
497518
else:
498519
assert_never(build_frontend)
499520

cibuildwheel/platforms/windows.py

Lines changed: 12 additions & 2 deletions
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 == "build[uv]"
250+
use_uv = build_frontend in {"build[uv]", "uv"}
251251
uv_path = find_uv()
252252

253253
log.step("Setting up build environment...")
@@ -357,7 +357,7 @@ def build(options: Options, tmp_path: Path) -> None:
357357
for config in python_configurations:
358358
build_options = options.build_options(config.identifier)
359359
build_frontend = build_options.build_frontend or BuildFrontendConfig("build")
360-
use_uv = build_frontend.name == "build[uv]" and can_use_uv(config)
360+
use_uv = build_frontend.name in {"build[uv]", "uv"} and can_use_uv(config)
361361
log.build_start(config.identifier)
362362

363363
identifier_tmp_dir = tmp_path / config.identifier
@@ -440,6 +440,16 @@ def build(options: Options, tmp_path: Path) -> None:
440440
*extra_flags,
441441
env=build_env,
442442
)
443+
elif build_frontend.name == "uv":
444+
call(
445+
"uv",
446+
"build",
447+
build_options.package_dir,
448+
"--wheel",
449+
f"--out-dir={built_wheel_dir}",
450+
*extra_flags,
451+
env=build_env,
452+
)
443453
else:
444454
assert_never(build_frontend)
445455

unit_test/options_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,11 @@ def test_environment_pass_references():
321321
"build",
322322
[],
323323
),
324+
(
325+
'build-frontend = "uv"',
326+
"uv",
327+
[],
328+
),
324329
(
325330
'build-frontend = {name = "build"}',
326331
"build",

0 commit comments

Comments
 (0)