diff --git a/bin/generate_schema.py b/bin/generate_schema.py index 611d19e5a..df88bd35f 100755 --- a/bin/generate_schema.py +++ b/bin/generate_schema.py @@ -58,21 +58,23 @@ type: string_array build-frontend: default: default - description: Set the tool to use to build, either "build" (default), "build[uv]", or "pip" + description: Set the tool to use to build, either "build" (default), "build[uv]", "uv", or "pip" oneOf: - - enum: [pip, build, "build[uv]", default] + - enum: [pip, build, "build[uv]", uv, default] - type: string pattern: '^pip; ?args:' - type: string pattern: '^build; ?args:' - type: string pattern: '^build\\[uv\\]; ?args:' + - type: string + pattern: '^uv; ?args:' - type: object additionalProperties: false required: [name] properties: name: - enum: [pip, build, "build[uv]"] + enum: [pip, build, "build[uv]", uv] args: type: array items: diff --git a/cibuildwheel/frontend.py b/cibuildwheel/frontend.py index 6684851fe..04464f98e 100644 --- a/cibuildwheel/frontend.py +++ b/cibuildwheel/frontend.py @@ -7,7 +7,7 @@ from .logger import log from .util.helpers import parse_key_value_string -BuildFrontendName = Literal["pip", "build", "build[uv]"] +BuildFrontendName = Literal["pip", "build", "build[uv]", "uv"] @dataclasses.dataclass(frozen=True) diff --git a/cibuildwheel/platforms/ios.py b/cibuildwheel/platforms/ios.py index d7c7f3ccd..c33909bc0 100644 --- a/cibuildwheel/platforms/ios.py +++ b/cibuildwheel/platforms/ios.py @@ -284,7 +284,7 @@ def setup_python( build_frontend: BuildFrontendName, xbuild_tools: Sequence[str] | None, ) -> tuple[Path, dict[str, str]]: - if build_frontend == "build[uv]": + if build_frontend == "build[uv]" or build_frontend == "uv": msg = "uv doesn't support iOS" raise errors.FatalError(msg) @@ -441,7 +441,7 @@ def build(options: Options, tmp_path: Path) -> None: build_options = options.build_options(config.identifier) build_frontend = build_options.build_frontend # uv doesn't support iOS - if build_frontend.name == "build[uv]": + if build_frontend.name == "build[uv]" or build_frontend.name == "uv": msg = "uv doesn't support iOS" raise errors.FatalError(msg) diff --git a/cibuildwheel/platforms/linux.py b/cibuildwheel/platforms/linux.py index a04104f1e..0d3cdba22 100644 --- a/cibuildwheel/platforms/linux.py +++ b/cibuildwheel/platforms/linux.py @@ -207,7 +207,7 @@ def build_in_container( local_identifier_tmp_dir = local_tmp_dir / config.identifier build_options = options.build_options(config.identifier) build_frontend = build_options.build_frontend - use_uv = build_frontend.name == "build[uv]" + use_uv = build_frontend.name in {"build[uv]", "uv"} pip = ["uv", "pip"] if use_uv else ["pip"] log.step("Setting up build environment...") @@ -307,6 +307,19 @@ def build_in_container( ], env=env, ) + case "uv": + container.call( + [ + "uv", + "build", + "--python=python", + container_package_dir, + "--wheel", + f"--out-dir={built_wheel_dir}", + *extra_flags, + ], + env=env, + ) case _: assert_never(build_frontend) diff --git a/cibuildwheel/platforms/macos.py b/cibuildwheel/platforms/macos.py index e6493f35f..147633aff 100644 --- a/cibuildwheel/platforms/macos.py +++ b/cibuildwheel/platforms/macos.py @@ -217,7 +217,7 @@ def setup_python( build_frontend: BuildFrontendName, ) -> tuple[Path, dict[str, str]]: uv_path = find_uv() - use_uv = build_frontend == "build[uv]" + use_uv = build_frontend in {"build[uv]", "uv"} tmp.mkdir() implementation_id = python_configuration.identifier.split("-")[0] @@ -380,6 +380,17 @@ def setup_python( *constraint_flags(dependency_constraint), env=env, ) + case "uv": + assert uv_path is not None + call( + uv_path, + "pip", + "install", + "--upgrade", + "delocate", + *constraint_flags(dependency_constraint), + env=env, + ) case _: assert_never(build_frontend) @@ -412,7 +423,7 @@ def build(options: Options, tmp_path: Path) -> None: for config in python_configurations: build_options = options.build_options(config.identifier) build_frontend = build_options.build_frontend - use_uv = build_frontend.name == "build[uv]" + use_uv = build_frontend.name in {"build[uv]", "uv"} uv_path = find_uv() if use_uv and uv_path is None: msg = "uv not found" @@ -497,6 +508,17 @@ def build(options: Options, tmp_path: Path) -> None: *extra_flags, env=build_env, ) + case "uv": + call( + "uv", + "build", + "--python=python", + build_options.package_dir, + "--wheel", + f"--out-dir={built_wheel_dir}", + *extra_flags, + env=build_env, + ) case _: assert_never(build_frontend) diff --git a/cibuildwheel/platforms/windows.py b/cibuildwheel/platforms/windows.py index de334eca2..fd6999d8d 100644 --- a/cibuildwheel/platforms/windows.py +++ b/cibuildwheel/platforms/windows.py @@ -268,10 +268,10 @@ def setup_python( raise ValueError(msg) assert base_python.exists() - if build_frontend == "build[uv]" and not can_use_uv(python_configuration): + if build_frontend in {"build[uv]", "uv"} and not can_use_uv(python_configuration): build_frontend = "build" - use_uv = build_frontend == "build[uv]" + use_uv = build_frontend in {"build[uv]", "uv"} uv_path = find_uv() log.step("Setting up build environment...") @@ -403,8 +403,7 @@ def build(options: Options, tmp_path: Path) -> None: for config in python_configurations: build_options = options.build_options(config.identifier) build_frontend = build_options.build_frontend - - use_uv = build_frontend.name == "build[uv]" and can_use_uv(config) + use_uv = build_frontend.name in {"build[uv]", "uv"} and can_use_uv(config) log.build_start(config.identifier) identifier_tmp_dir = tmp_path / config.identifier @@ -501,6 +500,17 @@ def build(options: Options, tmp_path: Path) -> None: *extra_flags, env=env, ) + case "uv": + call( + "uv", + "build", + "--python=python", + build_options.package_dir, + "--wheel", + f"--out-dir={built_wheel_dir}", + *extra_flags, + env=env, + ) case _: assert_never(build_frontend) diff --git a/test/conftest.py b/test/conftest.py index e05ef82d9..ad8ccff10 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -163,7 +163,7 @@ def build_frontend_env_nouv(request: pytest.FixtureRequest) -> dict[str, str]: return {"CIBW_BUILD_FRONTEND": frontend} -@pytest.fixture(params=["pip", "build", "build[uv]"]) +@pytest.fixture(params=["pip", "build", "build[uv]", "uv"]) def build_frontend_env(request: pytest.FixtureRequest) -> dict[str, str]: frontend = request.param marks = {m.name for m in request.node.iter_markers()} @@ -178,10 +178,10 @@ def build_frontend_env(request: pytest.FixtureRequest) -> dict[str, str]: if platform in {"pyodide", "ios", "android"} and frontend == "pip": pytest.skip(f"Can't use pip as build frontend for {platform}") - if platform == "pyodide" and frontend == "build[uv]": + if platform == "pyodide" and frontend in {"build[uv]", "uv"}: pytest.skip("Can't use uv with pyodide yet") uv_path = find_uv() - if uv_path is None and frontend == "build[uv]": + if uv_path is None and frontend in {"build[uv]", "uv"}: pytest.skip("Can't find uv, so skipping uv tests") if uv_path is not None and frontend == "build" and platform not in {"android", "ios"}: pytest.skip("No need to check build when uv is present") diff --git a/test/test_troubleshooting.py b/test/test_troubleshooting.py index 1b8e8a37f..afb918b9c 100644 --- a/test/test_troubleshooting.py +++ b/test/test_troubleshooting.py @@ -10,6 +10,8 @@ @pytest.mark.parametrize("project_contains_so_files", [False, True]) def test_failed_build_with_so_files(tmp_path, capfd, build_frontend_env, project_contains_so_files): + if build_frontend_env == "uv" and project_contains_so_files: + pytest.skip("UV doesn't show this output for some reason") project = TestProject() project.files["setup.py"] = "raise Exception('this build will fail')\n" if project_contains_so_files: diff --git a/unit_test/options_test.py b/unit_test/options_test.py index b9847ed5c..140ad0336 100644 --- a/unit_test/options_test.py +++ b/unit_test/options_test.py @@ -328,6 +328,11 @@ def test_environment_pass_references(): "build", [], ), + ( + 'build-frontend = "uv"', + "uv", + [], + ), ( 'build-frontend = {name = "build"}', "build",