From 7cf1646a44d882279cfea4038a3f1aea4c008bc9 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 30 Oct 2025 23:34:14 -0400 Subject: [PATCH] Expose `UV_NO_GROUP` as an environment variable (#16529) ## Summary Closes https://github.com/astral-sh/uv/issues/11619. --- crates/uv-cli/src/lib.rs | 8 ++-- crates/uv-static/src/env_vars.rs | 5 ++ crates/uv/tests/it/sync.rs | 78 ++++++++++++++++++++++++++++++++ docs/reference/cli.md | 8 ++-- docs/reference/environment.md | 6 +++ 5 files changed, 97 insertions(+), 8 deletions(-) diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index ee02181e2..d28d92019 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -3172,7 +3172,7 @@ pub struct RunArgs { /// `--all-groups`, and `--group`. /// /// May be provided multiple times. - #[arg(long)] + #[arg(long, env = EnvVars::UV_NO_GROUP, value_delimiter = ' ')] pub no_group: Vec, /// Ignore the default dependency groups. @@ -3501,7 +3501,7 @@ pub struct SyncArgs { /// `--all-groups`, and `--group`. /// /// May be provided multiple times. - #[arg(long)] + #[arg(long, env = EnvVars::UV_NO_GROUP, value_delimiter = ' ')] pub no_group: Vec, /// Ignore the default dependency groups. @@ -4178,7 +4178,7 @@ pub struct TreeArgs { /// `--all-groups`, and `--group`. /// /// May be provided multiple times. - #[arg(long)] + #[arg(long, env = EnvVars::UV_NO_GROUP, value_delimiter = ' ')] pub no_group: Vec, /// Ignore the default dependency groups. @@ -4353,7 +4353,7 @@ pub struct ExportArgs { /// `--all-groups`, and `--group`. /// /// May be provided multiple times. - #[arg(long)] + #[arg(long, env = EnvVars::UV_NO_GROUP, value_delimiter = ' ')] pub no_group: Vec, /// Ignore the default dependency groups. diff --git a/crates/uv-static/src/env_vars.rs b/crates/uv-static/src/env_vars.rs index fc073cf92..6e2bb5204 100644 --- a/crates/uv-static/src/env_vars.rs +++ b/crates/uv-static/src/env_vars.rs @@ -227,6 +227,11 @@ impl EnvVars { #[attr_added_in("0.8.7")] pub const UV_NO_DEV: &'static str = "UV_NO_DEV"; + /// Equivalent to the `--no-group` command-line argument. If set, uv will disable + /// the specified dependency groups for the given space-delimited list of packages. + #[attr_added_in("0.9.8")] + pub const UV_NO_GROUP: &'static str = "UV_NO_GROUP"; + /// Equivalent to the `--no-binary` command-line argument. If set, uv will install /// all packages from source. The resolver will still use pre-built wheels to /// extract package metadata, if available. diff --git a/crates/uv/tests/it/sync.rs b/crates/uv/tests/it/sync.rs index 566011a9e..3178edc1f 100644 --- a/crates/uv/tests/it/sync.rs +++ b/crates/uv/tests/it/sync.rs @@ -3414,6 +3414,84 @@ fn sync_exclude_group() -> Result<()> { Ok(()) } +#[test] +fn sync_exclude_group_with_environment_variable() -> Result<()> { + let context = TestContext::new("3.12"); + + let pyproject_toml = context.temp_dir.child("pyproject.toml"); + pyproject_toml.write_str( + r#" + [project] + name = "project" + version = "0.1.0" + requires-python = ">=3.12" + dependencies = ["typing-extensions"] + + [dependency-groups] + foo = ["anyio"] + bar = ["iniconfig"] + baz = ["certifi"] + "#, + )?; + + context.lock().assert().success(); + + // Test single group exclusion via environment variable + uv_snapshot!(context.filters(), context.sync() + .arg("--group").arg("foo") + .arg("--group").arg("bar") + .env("UV_NO_GROUP", "bar"), @r" + success: true + exit_code: 0 + ----- stdout ----- + + ----- stderr ----- + Resolved 7 packages in [TIME] + Prepared 4 packages in [TIME] + Installed 4 packages in [TIME] + + anyio==4.3.0 + + idna==3.6 + + sniffio==1.3.1 + + typing-extensions==4.10.0 + "); + + // Test multiple group exclusion via environment variable (space-separated) + uv_snapshot!(context.filters(), context.sync() + .arg("--group").arg("foo") + .arg("--group").arg("bar") + .arg("--group").arg("baz") + .env("UV_NO_GROUP", "bar baz"), @r" + success: true + exit_code: 0 + ----- stdout ----- + + ----- stderr ----- + Resolved 7 packages in [TIME] + Audited 4 packages in [TIME] + "); + + // Test that CLI flag takes precedence over environment variable + // When --no-group is used on CLI, it overrides UV_NO_GROUP env var + uv_snapshot!(context.filters(), context.sync() + .arg("--group").arg("foo") + .arg("--group").arg("bar") + .arg("--group").arg("baz") + .arg("--no-group").arg("bar") + .env("UV_NO_GROUP", "baz"), @r" + success: true + exit_code: 0 + ----- stdout ----- + + ----- stderr ----- + Resolved 7 packages in [TIME] + Prepared 1 package in [TIME] + Installed 1 package in [TIME] + + certifi==2024.2.2 + "); + + Ok(()) +} + #[test] fn sync_dev_group() -> Result<()> { let context = TestContext::new("3.12"); diff --git a/docs/reference/cli.md b/docs/reference/cli.md index be08c8aac..dbea7db0b 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -495,7 +495,7 @@ uv run [OPTIONS] [COMMAND]
--no-group no-group

Disable the specified dependency group.

This option always takes precedence over default groups, --all-groups, and --group.

May be provided multiple times.

-
--no-index

Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those provided via --find-links

+

May also be set with the UV_NO_GROUP environment variable.

--no-index

Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those provided via --find-links

--no-managed-python

Disable use of uv-managed Python versions.

Instead, uv will search for a suitable Python version on the system.

May also be set with the UV_NO_MANAGED_PYTHON environment variable.

--no-progress

Hide all progress outputs.

@@ -1485,7 +1485,7 @@ uv sync [OPTIONS]
--no-group no-group

Disable the specified dependency group.

This option always takes precedence over default groups, --all-groups, and --group.

May be provided multiple times.

-
--no-index

Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those provided via --find-links

+

May also be set with the UV_NO_GROUP environment variable.

--no-index

Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those provided via --find-links

--no-install-local

Do not install local path dependencies

Skips the current project, workspace members, and any other local (path or editable) packages. Only remote/indexed dependencies are installed. Useful in Docker builds to cache heavy third-party dependencies first and layer local packages separately.

--no-install-package no-install-package

Do not install the given package(s).

@@ -1926,7 +1926,7 @@ uv export [OPTIONS]
--no-group no-group

Disable the specified dependency group.

This option always takes precedence over default groups, --all-groups, and --group.

May be provided multiple times.

-
--no-hashes

Omit hashes in the generated output

+

May also be set with the UV_NO_GROUP environment variable.

--no-hashes

Omit hashes in the generated output

--no-header

Exclude the comment header at the top of the generated output file

--no-index

Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those provided via --find-links

--no-managed-python

Disable use of uv-managed Python versions.

@@ -2109,7 +2109,7 @@ uv tree [OPTIONS]

May also be set with the UV_NO_DEV environment variable.

--no-group no-group

Disable the specified dependency group.

This option always takes precedence over default groups, --all-groups, and --group.

May be provided multiple times.

-
--no-index

Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those provided via --find-links

+

May also be set with the UV_NO_GROUP environment variable.

--no-index

Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those provided via --find-links

--no-managed-python

Disable use of uv-managed Python versions.

Instead, uv will search for a suitable Python version on the system.

May also be set with the UV_NO_MANAGED_PYTHON environment variable.

--no-progress

Hide all progress outputs.

diff --git a/docs/reference/environment.md b/docs/reference/environment.md index f362853d0..eb0daae6e 100644 --- a/docs/reference/environment.md +++ b/docs/reference/environment.md @@ -346,6 +346,12 @@ Ignore `.env` files when executing `uv run` commands. Disable GitHub-specific requests that allow uv to skip `git fetch` in some circumstances. +### `UV_NO_GROUP` +added in `0.9.8` + +Equivalent to the `--no-group` command-line argument. If set, uv will disable +the specified dependency groups for the given space-delimited list of packages. + ### `UV_NO_HF_TOKEN` added in `0.8.1`