Skip to content

Commit

Permalink
Accept requirements in uv remove
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jan 6, 2025
1 parent 0d57d29 commit 088df77
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3272,7 +3272,7 @@ pub struct AddArgs {
pub struct RemoveArgs {
/// The names of the dependencies to remove (e.g., `ruff`).
#[arg(required = true)]
pub packages: Vec<PackageName>,
pub packages: Vec<Requirement<VerbatimParsedUrl>>,

/// Remove the packages from the development dependency group.
///
Expand Down
4 changes: 3 additions & 1 deletion crates/uv-settings/src/settings.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use serde::{Deserialize, Serialize};
use std::{fmt::Debug, num::NonZeroUsize, path::PathBuf};

use serde::{Deserialize, Serialize};
use url::Url;

use uv_cache_info::CacheKey;
use uv_configuration::{
ConfigSettings, IndexStrategy, KeyringProviderType, PackageNameSpecifier, RequiredVersion,
Expand Down
6 changes: 6 additions & 0 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::process;
use std::str::FromStr;

use url::Url;

use uv_cache::{CacheArgs, Refresh};
use uv_cli::comma::CommaSeparatedRequirements;
use uv_cli::{
Expand Down Expand Up @@ -1251,6 +1252,11 @@ impl RemoveSettings {
.map(|fs| fs.install_mirrors.clone())
.unwrap_or_default();

let packages = packages
.into_iter()
.map(|requirement| requirement.name)
.collect();

Self {
locked,
frozen,
Expand Down
53 changes: 53 additions & 0 deletions crates/uv/tests/it/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8386,3 +8386,56 @@ fn add_no_indent() -> Result<()> {
});
Ok(())
}

/// Accept requirements, not just package names, in `uv remove`.
#[test]
fn remove_requirement() -> Result<()> {
let context = TestContext::new("3.12");

let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(indoc! {r#"
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["flask"]
[build-system]
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"
"#})?;

uv_snapshot!(context.filters(), context.remove().arg("flask[dotenv]"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 1 package in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
+ project==0.1.0 (from file://[TEMP_DIR]/)
"###);

let pyproject_toml = context.read("pyproject.toml");

insta::with_settings!({
filters => context.filters(),
}, {
assert_snapshot!(
pyproject_toml, @r###"
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = []
[build-system]
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"
"###
);
});

Ok(())
}

0 comments on commit 088df77

Please sign in to comment.