diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index f3fac3907..d168adf50 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -4818,7 +4818,13 @@ pub struct BuildOptionsArgs { /// When enabled, resolving will not run arbitrary Python code. The cached wheels of /// already-built source distributions will be reused, but operations that require building /// distributions will exit with an error. - #[arg(long, overrides_with("build"), help_heading = "Build options")] + #[arg( + long, + env = EnvVars::UV_NO_BUILD, + overrides_with("build"), + value_parser = clap::builder::BoolishValueParser::new(), + help_heading = "Build options", + )] pub no_build: bool, #[arg( @@ -4830,7 +4836,7 @@ pub struct BuildOptionsArgs { pub build: bool, /// Don't build source distributions for a specific package. - #[arg(long, help_heading = "Build options")] + #[arg(long, help_heading = "Build options", env = EnvVars::UV_NO_BUILD_PACKAGE, value_delimiter = ' ')] pub no_build_package: Vec, /// Don't install pre-built wheels. diff --git a/crates/uv-static/src/env_vars.rs b/crates/uv-static/src/env_vars.rs index 636e2386c..953cc2354 100644 --- a/crates/uv-static/src/env_vars.rs +++ b/crates/uv-static/src/env_vars.rs @@ -162,6 +162,14 @@ impl EnvVars { /// not use pre-built wheels for the given space-delimited list of packages. pub const UV_NO_BINARY_PACKAGE: &'static str = "UV_NO_BINARY_PACKAGE"; + /// Equivalent to the `--no-build` command-line argument. If set, uv will not build + /// source distributions. + pub const UV_NO_BUILD: &'static str = "UV_NO_BUILD"; + + /// Equivalent to the `--no-build-package` command line argument. If set, uv will + /// not build source distributions for the given space-delimited list of packages. + pub const UV_NO_BUILD_PACKAGE: &'static str = "UV_NO_BUILD_PACKAGE"; + /// Equivalent to the `--publish-url` command-line argument. The URL of the upload /// endpoint of the index to use with `uv publish`. pub const UV_PUBLISH_URL: &'static str = "UV_PUBLISH_URL"; diff --git a/crates/uv/tests/it/sync.rs b/crates/uv/tests/it/sync.rs index 6f2d0e06f..65a0ea636 100644 --- a/crates/uv/tests/it/sync.rs +++ b/crates/uv/tests/it/sync.rs @@ -4543,6 +4543,19 @@ fn no_build() -> Result<()> { assert!(context.temp_dir.child("uv.lock").exists()); + uv_snapshot!(context.filters(), context.sync().arg("--reinstall").env("UV_NO_BUILD_PACKAGE", "iniconfig"), @r###" + success: true + exit_code: 0 + ----- stdout ----- + + ----- stderr ----- + Resolved 2 packages in [TIME] + Prepared 1 package in [TIME] + Uninstalled 1 package in [TIME] + Installed 1 package in [TIME] + ~ iniconfig==2.0.0 + "###); + Ok(()) } @@ -4573,6 +4586,47 @@ fn no_build_error() -> Result<()> { error: Distribution `django-allauth==0.51.0 @ registry+https://pypi.org/simple` can't be installed because it is marked as `--no-build` but has no binary distribution "###); + uv_snapshot!(context.filters(), context.sync().arg("--no-build"), @r###" + success: false + exit_code: 2 + ----- stdout ----- + + ----- stderr ----- + Resolved 19 packages in [TIME] + error: Distribution `project==0.1.0 @ virtual+.` can't be installed because it is marked as `--no-build` but has no binary distribution + "###); + + uv_snapshot!(context.filters(), context.sync().arg("--reinstall").env("UV_NO_BUILD", "1"), @r###" + success: false + exit_code: 2 + ----- stdout ----- + + ----- stderr ----- + Resolved 19 packages in [TIME] + error: Distribution `project==0.1.0 @ virtual+.` can't be installed because it is marked as `--no-build` but has no binary distribution + "###); + + uv_snapshot!(context.filters(), context.sync().arg("--reinstall").env("UV_NO_BUILD_PACKAGE", "django-allauth"), @r###" + success: false + exit_code: 2 + ----- stdout ----- + + ----- stderr ----- + Resolved 19 packages in [TIME] + error: Distribution `django-allauth==0.51.0 @ registry+https://pypi.org/simple` can't be installed because it is marked as `--no-build` but has no binary distribution + "###); + + uv_snapshot!(context.filters(), context.sync().arg("--reinstall").env("UV_NO_BUILD", "django-allauth"), @r###" + success: false + exit_code: 2 + ----- stdout ----- + + ----- stderr ----- + error: invalid value 'django-allauth' for '--no-build': value was not a boolean + + For more information, try '--help'. + "###); + assert!(context.temp_dir.child("uv.lock").exists()); Ok(()) diff --git a/docs/configuration/environment.md b/docs/configuration/environment.md index 3d19b2d67..06c5d128e 100644 --- a/docs/configuration/environment.md +++ b/docs/configuration/environment.md @@ -195,11 +195,21 @@ extract package metadata, if available. Equivalent to the `--no-binary-package` command line argument. If set, uv will not use pre-built wheels for the given space-delimited list of packages. +### `UV_NO_BUILD` + +Equivalent to the `--no-build` command-line argument. If set, uv will not build +source distributions. + ### `UV_NO_BUILD_ISOLATION` Equivalent to the `--no-build-isolation` command-line argument. If set, uv will skip isolation when building source distributions. +### `UV_NO_BUILD_PACKAGE` + +Equivalent to the `--no-build-package` command line argument. If set, uv will +not build source distributions for the given space-delimited list of packages. + ### `UV_NO_CACHE` Equivalent to the `--no-cache` command-line argument. If set, uv will not use the diff --git a/docs/reference/cli.md b/docs/reference/cli.md index 8b4206656..79c90ae36 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -307,6 +307,7 @@ uv run [OPTIONS] [COMMAND]

When enabled, resolving will not run arbitrary Python code. The cached wheels of already-built source distributions will be reused, but operations that require building distributions will exit with an error.

+

May also be set with the UV_NO_BUILD environment variable.

--no-build-isolation

Disable isolation when building source distributions.

Assumes that build dependencies specified by PEP 518 are already installed.

@@ -318,6 +319,7 @@ uv run [OPTIONS] [COMMAND]
--no-build-package no-build-package

Don’t build source distributions for a specific package

+

May also be set with the UV_NO_BUILD_PACKAGE environment variable.

--no-cache, -n

Avoid reading from or writing to the cache, instead using a temporary directory for the duration of the operation

May also be set with the UV_NO_CACHE environment variable.

@@ -968,6 +970,7 @@ uv add [OPTIONS] >

When enabled, resolving will not run arbitrary Python code. The cached wheels of already-built source distributions will be reused, but operations that require building distributions will exit with an error.

+

May also be set with the UV_NO_BUILD environment variable.

--no-build-isolation

Disable isolation when building source distributions.

Assumes that build dependencies specified by PEP 518 are already installed.

@@ -979,6 +982,7 @@ uv add [OPTIONS] >
--no-build-package no-build-package

Don’t build source distributions for a specific package

+

May also be set with the UV_NO_BUILD_PACKAGE environment variable.

--no-cache, -n

Avoid reading from or writing to the cache, instead using a temporary directory for the duration of the operation

May also be set with the UV_NO_CACHE environment variable.

@@ -1331,6 +1335,7 @@ uv remove [OPTIONS] ...

When enabled, resolving will not run arbitrary Python code. The cached wheels of already-built source distributions will be reused, but operations that require building distributions will exit with an error.

+

May also be set with the UV_NO_BUILD environment variable.

--no-build-isolation

Disable isolation when building source distributions.

Assumes that build dependencies specified by PEP 518 are already installed.

@@ -1342,6 +1347,7 @@ uv remove [OPTIONS] ...
--no-build-package no-build-package

Don’t build source distributions for a specific package

+

May also be set with the UV_NO_BUILD_PACKAGE environment variable.

--no-cache, -n

Avoid reading from or writing to the cache, instead using a temporary directory for the duration of the operation

May also be set with the UV_NO_CACHE environment variable.

@@ -1706,6 +1712,7 @@ uv sync [OPTIONS]

When enabled, resolving will not run arbitrary Python code. The cached wheels of already-built source distributions will be reused, but operations that require building distributions will exit with an error.

+

May also be set with the UV_NO_BUILD environment variable.

--no-build-isolation

Disable isolation when building source distributions.

Assumes that build dependencies specified by PEP 518 are already installed.

@@ -1717,6 +1724,7 @@ uv sync [OPTIONS]
--no-build-package no-build-package

Don’t build source distributions for a specific package

+

May also be set with the UV_NO_BUILD_PACKAGE environment variable.

--no-cache, -n

Avoid reading from or writing to the cache, instead using a temporary directory for the duration of the operation

May also be set with the UV_NO_CACHE environment variable.

@@ -2079,6 +2087,7 @@ uv lock [OPTIONS]

When enabled, resolving will not run arbitrary Python code. The cached wheels of already-built source distributions will be reused, but operations that require building distributions will exit with an error.

+

May also be set with the UV_NO_BUILD environment variable.

--no-build-isolation

Disable isolation when building source distributions.

Assumes that build dependencies specified by PEP 518 are already installed.

@@ -2090,6 +2099,7 @@ uv lock [OPTIONS]
--no-build-package no-build-package

Don’t build source distributions for a specific package

+

May also be set with the UV_NO_BUILD_PACKAGE environment variable.

--no-cache, -n

Avoid reading from or writing to the cache, instead using a temporary directory for the duration of the operation

May also be set with the UV_NO_CACHE environment variable.

@@ -2426,6 +2436,7 @@ uv export [OPTIONS]

When enabled, resolving will not run arbitrary Python code. The cached wheels of already-built source distributions will be reused, but operations that require building distributions will exit with an error.

+

May also be set with the UV_NO_BUILD environment variable.

--no-build-isolation

Disable isolation when building source distributions.

Assumes that build dependencies specified by PEP 518 are already installed.

@@ -2437,6 +2448,7 @@ uv export [OPTIONS]
--no-build-package no-build-package

Don’t build source distributions for a specific package

+

May also be set with the UV_NO_BUILD_PACKAGE environment variable.

--no-cache, -n

Avoid reading from or writing to the cache, instead using a temporary directory for the duration of the operation

May also be set with the UV_NO_CACHE environment variable.

@@ -2806,6 +2818,7 @@ uv tree [OPTIONS]

When enabled, resolving will not run arbitrary Python code. The cached wheels of already-built source distributions will be reused, but operations that require building distributions will exit with an error.

+

May also be set with the UV_NO_BUILD environment variable.

--no-build-isolation

Disable isolation when building source distributions.

Assumes that build dependencies specified by PEP 518 are already installed.

@@ -2817,6 +2830,7 @@ uv tree [OPTIONS]
--no-build-package no-build-package

Don’t build source distributions for a specific package

+

May also be set with the UV_NO_BUILD_PACKAGE environment variable.

--no-cache, -n

Avoid reading from or writing to the cache, instead using a temporary directory for the duration of the operation

May also be set with the UV_NO_CACHE environment variable.

@@ -3288,6 +3302,7 @@ uv tool run [OPTIONS] [COMMAND]

When enabled, resolving will not run arbitrary Python code. The cached wheels of already-built source distributions will be reused, but operations that require building distributions will exit with an error.

+

May also be set with the UV_NO_BUILD environment variable.

--no-build-isolation

Disable isolation when building source distributions.

Assumes that build dependencies specified by PEP 518 are already installed.

@@ -3299,6 +3314,7 @@ uv tool run [OPTIONS] [COMMAND]
--no-build-package no-build-package

Don’t build source distributions for a specific package

+

May also be set with the UV_NO_BUILD_PACKAGE environment variable.

--no-cache, -n

Avoid reading from or writing to the cache, instead using a temporary directory for the duration of the operation

May also be set with the UV_NO_CACHE environment variable.

@@ -3626,6 +3642,7 @@ uv tool install [OPTIONS]

When enabled, resolving will not run arbitrary Python code. The cached wheels of already-built source distributions will be reused, but operations that require building distributions will exit with an error.

+

May also be set with the UV_NO_BUILD environment variable.

--no-build-isolation

Disable isolation when building source distributions.

Assumes that build dependencies specified by PEP 518 are already installed.

@@ -3637,6 +3654,7 @@ uv tool install [OPTIONS]
--no-build-package no-build-package

Don’t build source distributions for a specific package

+

May also be set with the UV_NO_BUILD_PACKAGE environment variable.

--no-cache, -n

Avoid reading from or writing to the cache, instead using a temporary directory for the duration of the operation

May also be set with the UV_NO_CACHE environment variable.

@@ -3951,6 +3969,7 @@ uv tool upgrade [OPTIONS] ...

When enabled, resolving will not run arbitrary Python code. The cached wheels of already-built source distributions will be reused, but operations that require building distributions will exit with an error.

+

May also be set with the UV_NO_BUILD environment variable.

--no-build-isolation

Disable isolation when building source distributions.

Assumes that build dependencies specified by PEP 518 are already installed.

@@ -3962,6 +3981,7 @@ uv tool upgrade [OPTIONS] ...
--no-build-package no-build-package

Don’t build source distributions for a specific package

+

May also be set with the UV_NO_BUILD_PACKAGE environment variable.

--no-cache, -n

Avoid reading from or writing to the cache, instead using a temporary directory for the duration of the operation

May also be set with the UV_NO_CACHE environment variable.

@@ -8397,6 +8417,7 @@ uv build [OPTIONS] [SRC]

When enabled, resolving will not run arbitrary Python code. The cached wheels of already-built source distributions will be reused, but operations that require building distributions will exit with an error.

+

May also be set with the UV_NO_BUILD environment variable.

--no-build-isolation

Disable isolation when building source distributions.

Assumes that build dependencies specified by PEP 518 are already installed.

@@ -8410,6 +8431,7 @@ uv build [OPTIONS] [SRC]
--no-build-package no-build-package

Don’t build source distributions for a specific package

+

May also be set with the UV_NO_BUILD_PACKAGE environment variable.

--no-cache, -n

Avoid reading from or writing to the cache, instead using a temporary directory for the duration of the operation

May also be set with the UV_NO_CACHE environment variable.