Do not allow uv add --group ... --script (#13997)

## Summary

Closes #13988 

## Test Plan

`cargo test`
This commit is contained in:
Ahmed Ilyas 2025-06-12 16:45:12 +02:00 committed by GitHub
parent 806cc5cad9
commit a1f9f28762
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 60 additions and 4 deletions

View file

@ -3516,7 +3516,12 @@ pub struct AddArgs {
/// Add the requirements to the development dependency group. /// Add the requirements to the development dependency group.
/// ///
/// This option is an alias for `--group dev`. /// This option is an alias for `--group dev`.
#[arg(long, conflicts_with("optional"), conflicts_with("group"))] #[arg(
long,
conflicts_with("optional"),
conflicts_with("group"),
conflicts_with("script")
)]
pub dev: bool, pub dev: bool,
/// Add the requirements to the package's optional dependencies for the specified extra. /// Add the requirements to the package's optional dependencies for the specified extra.
@ -3530,7 +3535,12 @@ pub struct AddArgs {
/// Add the requirements to the specified dependency group. /// Add the requirements to the specified dependency group.
/// ///
/// These requirements will not be included in the published metadata for the project. /// These requirements will not be included in the published metadata for the project.
#[arg(long, conflicts_with("dev"), conflicts_with("optional"))] #[arg(
long,
conflicts_with("dev"),
conflicts_with("optional"),
conflicts_with("script")
)]
pub group: Option<GroupName>, pub group: Option<GroupName>,
/// Add the requirements as editable. /// Add the requirements as editable.
@ -3677,11 +3687,21 @@ pub struct RemoveArgs {
pub dev: bool, pub dev: bool,
/// Remove the packages from the project's optional dependencies for the specified extra. /// Remove the packages from the project's optional dependencies for the specified extra.
#[arg(long, conflicts_with("dev"), conflicts_with("group"))] #[arg(
long,
conflicts_with("dev"),
conflicts_with("group"),
conflicts_with("script")
)]
pub optional: Option<ExtraName>, pub optional: Option<ExtraName>,
/// Remove the packages from the specified dependency group. /// Remove the packages from the specified dependency group.
#[arg(long, conflicts_with("dev"), conflicts_with("optional"))] #[arg(
long,
conflicts_with("dev"),
conflicts_with("optional"),
conflicts_with("script")
)]
pub group: Option<GroupName>, pub group: Option<GroupName>,
/// Avoid syncing the virtual environment after re-locking the project. /// Avoid syncing the virtual environment after re-locking the project.

View file

@ -2013,6 +2013,42 @@ fn remove_both_dev() -> Result<()> {
Ok(()) Ok(())
} }
/// Do not allow add for groups in scripts.
#[test]
fn disallow_group_script_add() -> Result<()> {
let context = TestContext::new("3.12");
let script = context.temp_dir.child("main.py");
script.write_str(indoc! {r#"
# /// script
# requires-python = ">=3.13"
# dependencies = []
#
# ///
"#})?;
uv_snapshot!(context.filters(), context
.add()
.arg("--group")
.arg("dev")
.arg("anyio==3.7.0")
.arg("--script")
.arg("main.py"), @r###"
success: false
exit_code: 2
----- stdout -----
----- stderr -----
error: the argument '--group <GROUP>' cannot be used with '--script <SCRIPT>'
Usage: uv add --cache-dir [CACHE_DIR] --group <GROUP> --exclude-newer <EXCLUDE_NEWER> <PACKAGES|--requirements <REQUIREMENTS>>
For more information, try '--help'.
"###);
Ok(())
}
/// `uv remove --group dev` should remove from both `dev-dependencies` and `dependency-groups.dev`. /// `uv remove --group dev` should remove from both `dev-dependencies` and `dependency-groups.dev`.
#[test] #[test]
fn remove_both_dev_group() -> Result<()> { fn remove_both_dev_group() -> Result<()> {