From a1f9f28762b113dcecd07fd739f77c1bb417a53d Mon Sep 17 00:00:00 2001 From: Ahmed Ilyas Date: Thu, 12 Jun 2025 16:45:12 +0200 Subject: [PATCH] Do not allow `uv add --group ... --script` (#13997) ## Summary Closes #13988 ## Test Plan `cargo test` --- crates/uv-cli/src/lib.rs | 28 ++++++++++++++++++++++++---- crates/uv/tests/it/edit.rs | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index e29387b28..0b96875e5 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -3516,7 +3516,12 @@ pub struct AddArgs { /// Add the requirements to the development dependency group. /// /// 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, /// 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. /// /// 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, /// Add the requirements as editable. @@ -3677,11 +3687,21 @@ pub struct RemoveArgs { pub dev: bool, /// 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, /// 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, /// Avoid syncing the virtual environment after re-locking the project. diff --git a/crates/uv/tests/it/edit.rs b/crates/uv/tests/it/edit.rs index 5ba64fca2..f96dd7b7b 100644 --- a/crates/uv/tests/it/edit.rs +++ b/crates/uv/tests/it/edit.rs @@ -2013,6 +2013,42 @@ fn remove_both_dev() -> Result<()> { 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 ' cannot be used with '--script