From 8289e38e8f06883ee1adca4c69708dff43f16340 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Tue, 22 Jul 2025 14:10:08 -0500 Subject: [PATCH] Add `UV_INIT_BUILD_BACKEND` (#14821) Closes https://github.com/astral-sh/uv/issues/14820 --- crates/uv-cli/src/lib.rs | 2 +- crates/uv-static/src/env_vars.rs | 4 ++++ docs/reference/cli.md | 2 +- docs/reference/environment.md | 5 +++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index e1084f035..b6a41f3e7 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -2891,7 +2891,7 @@ pub struct InitArgs { /// Initialize a build-backend of choice for the project. /// /// Implicitly sets `--package`. - #[arg(long, value_enum, conflicts_with_all=["script", "no_package"])] + #[arg(long, value_enum, conflicts_with_all=["script", "no_package"], env = EnvVars::UV_INIT_BUILD_BACKEND)] pub build_backend: Option, /// Invalid option name for build backend. diff --git a/crates/uv-static/src/env_vars.rs b/crates/uv-static/src/env_vars.rs index 0e99ec549..a18bc11a8 100644 --- a/crates/uv-static/src/env_vars.rs +++ b/crates/uv-static/src/env_vars.rs @@ -257,6 +257,10 @@ impl EnvVars { /// Specifies the "bin" directory for installing tool executables. pub const UV_TOOL_BIN_DIR: &'static str = "UV_TOOL_BIN_DIR"; + /// Equivalent to the `--build-backend` argument for `uv init`. Determines the default backend + /// to use when creating a new project. + pub const UV_INIT_BUILD_BACKEND: &'static str = "UV_INIT_BUILD_BACKEND"; + /// Specifies the path to the directory to use for a project virtual environment. /// /// See the [project documentation](../concepts/projects/config.md#project-environment-path) diff --git a/docs/reference/cli.md b/docs/reference/cli.md index 409ef5911..9b27ea5cb 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -302,7 +302,7 @@ uv init [OPTIONS] [PATH]

Disables creating extra files like README.md, the src/ tree, .python-version files, etc.

--build-backend build-backend

Initialize a build-backend of choice for the project.

Implicitly sets --package.

-

Possible values:

+

May also be set with the UV_INIT_BUILD_BACKEND environment variable.

Possible values:

  • hatch: Use hatchling as the project build backend
  • flit: Use flit-core as the project build backend
  • diff --git a/docs/reference/environment.md b/docs/reference/environment.md index a4d686192..6b93dbe7e 100644 --- a/docs/reference/environment.md +++ b/docs/reference/environment.md @@ -147,6 +147,11 @@ Provides the HTTP Basic authentication username for a named index. The `name` parameter is the name of the index. For example, given an index named `foo`, the environment variable key would be `UV_INDEX_FOO_USERNAME`. +### `UV_INIT_BUILD_BACKEND` + +Equivalent to the `--build-backend` argument for `uv init`. Determines the default backend +to use when creating a new project. + ### `UV_INSECURE_HOST` Equivalent to the `--allow-insecure-host` argument.