Expose UV_NO_GROUP as an environment variable (#16529)

## Summary

Closes https://github.com/astral-sh/uv/issues/11619.
This commit is contained in:
Charlie Marsh 2025-10-30 23:34:14 -04:00 committed by GitHub
parent d71ae61c0b
commit 7cf1646a44
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 97 additions and 8 deletions

View file

@ -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<GroupName>,
/// 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<GroupName>,
/// 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<GroupName>,
/// 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<GroupName>,
/// Ignore the default dependency groups.

View file

@ -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.

View file

@ -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");