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

View file

@ -495,7 +495,7 @@ uv run [OPTIONS] [COMMAND]
</dd><dt id="uv-run--no-group"><a href="#uv-run--no-group"><code>--no-group</code></a> <i>no-group</i></dt><dd><p>Disable the specified dependency group.</p>
<p>This option always takes precedence over default groups, <code>--all-groups</code>, and <code>--group</code>.</p>
<p>May be provided multiple times.</p>
</dd><dt id="uv-run--no-index"><a href="#uv-run--no-index"><code>--no-index</code></a></dt><dd><p>Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those provided via <code>--find-links</code></p>
<p>May also be set with the <code>UV_NO_GROUP</code> environment variable.</p></dd><dt id="uv-run--no-index"><a href="#uv-run--no-index"><code>--no-index</code></a></dt><dd><p>Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those provided via <code>--find-links</code></p>
</dd><dt id="uv-run--no-managed-python"><a href="#uv-run--no-managed-python"><code>--no-managed-python</code></a></dt><dd><p>Disable use of uv-managed Python versions.</p>
<p>Instead, uv will search for a suitable Python version on the system.</p>
<p>May also be set with the <code>UV_NO_MANAGED_PYTHON</code> environment variable.</p></dd><dt id="uv-run--no-progress"><a href="#uv-run--no-progress"><code>--no-progress</code></a></dt><dd><p>Hide all progress outputs.</p>
@ -1485,7 +1485,7 @@ uv sync [OPTIONS]
</dd><dt id="uv-sync--no-group"><a href="#uv-sync--no-group"><code>--no-group</code></a> <i>no-group</i></dt><dd><p>Disable the specified dependency group.</p>
<p>This option always takes precedence over default groups, <code>--all-groups</code>, and <code>--group</code>.</p>
<p>May be provided multiple times.</p>
</dd><dt id="uv-sync--no-index"><a href="#uv-sync--no-index"><code>--no-index</code></a></dt><dd><p>Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those provided via <code>--find-links</code></p>
<p>May also be set with the <code>UV_NO_GROUP</code> environment variable.</p></dd><dt id="uv-sync--no-index"><a href="#uv-sync--no-index"><code>--no-index</code></a></dt><dd><p>Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those provided via <code>--find-links</code></p>
</dd><dt id="uv-sync--no-install-local"><a href="#uv-sync--no-install-local"><code>--no-install-local</code></a></dt><dd><p>Do not install local path dependencies</p>
<p>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.</p>
</dd><dt id="uv-sync--no-install-package"><a href="#uv-sync--no-install-package"><code>--no-install-package</code></a> <i>no-install-package</i></dt><dd><p>Do not install the given package(s).</p>
@ -1926,7 +1926,7 @@ uv export [OPTIONS]
</dd><dt id="uv-export--no-group"><a href="#uv-export--no-group"><code>--no-group</code></a> <i>no-group</i></dt><dd><p>Disable the specified dependency group.</p>
<p>This option always takes precedence over default groups, <code>--all-groups</code>, and <code>--group</code>.</p>
<p>May be provided multiple times.</p>
</dd><dt id="uv-export--no-hashes"><a href="#uv-export--no-hashes"><code>--no-hashes</code></a></dt><dd><p>Omit hashes in the generated output</p>
<p>May also be set with the <code>UV_NO_GROUP</code> environment variable.</p></dd><dt id="uv-export--no-hashes"><a href="#uv-export--no-hashes"><code>--no-hashes</code></a></dt><dd><p>Omit hashes in the generated output</p>
</dd><dt id="uv-export--no-header"><a href="#uv-export--no-header"><code>--no-header</code></a></dt><dd><p>Exclude the comment header at the top of the generated output file</p>
</dd><dt id="uv-export--no-index"><a href="#uv-export--no-index"><code>--no-index</code></a></dt><dd><p>Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those provided via <code>--find-links</code></p>
</dd><dt id="uv-export--no-managed-python"><a href="#uv-export--no-managed-python"><code>--no-managed-python</code></a></dt><dd><p>Disable use of uv-managed Python versions.</p>
@ -2109,7 +2109,7 @@ uv tree [OPTIONS]
<p>May also be set with the <code>UV_NO_DEV</code> environment variable.</p></dd><dt id="uv-tree--no-group"><a href="#uv-tree--no-group"><code>--no-group</code></a> <i>no-group</i></dt><dd><p>Disable the specified dependency group.</p>
<p>This option always takes precedence over default groups, <code>--all-groups</code>, and <code>--group</code>.</p>
<p>May be provided multiple times.</p>
</dd><dt id="uv-tree--no-index"><a href="#uv-tree--no-index"><code>--no-index</code></a></dt><dd><p>Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those provided via <code>--find-links</code></p>
<p>May also be set with the <code>UV_NO_GROUP</code> environment variable.</p></dd><dt id="uv-tree--no-index"><a href="#uv-tree--no-index"><code>--no-index</code></a></dt><dd><p>Ignore the registry index (e.g., PyPI), instead relying on direct URL dependencies and those provided via <code>--find-links</code></p>
</dd><dt id="uv-tree--no-managed-python"><a href="#uv-tree--no-managed-python"><code>--no-managed-python</code></a></dt><dd><p>Disable use of uv-managed Python versions.</p>
<p>Instead, uv will search for a suitable Python version on the system.</p>
<p>May also be set with the <code>UV_NO_MANAGED_PYTHON</code> environment variable.</p></dd><dt id="uv-tree--no-progress"><a href="#uv-tree--no-progress"><code>--no-progress</code></a></dt><dd><p>Hide all progress outputs.</p>

View file

@ -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`
<small class="added-in">added in `0.9.8`</small>
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`
<small class="added-in">added in `0.8.1`</small>