Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes bug in uv remove when only comments exist #10484

Merged
merged 2 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions crates/uv-workspace/src/pyproject_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1272,15 +1272,11 @@ fn reformat_array_multiline(deps: &mut Array) {
.map(|(s, _)| s)
.unwrap_or(decor_prefix);

// If there is no indentation, use four-space.
indentation_prefix = Some(if decor_prefix.is_empty() {
" ".to_string()
} else {
decor_prefix.to_string()
});
indentation_prefix = (!decor_prefix.is_empty()).then_some(decor_prefix.to_string());
}

let indentation_prefix_str = format!("\n{}", indentation_prefix.as_ref().unwrap());
let indentation_prefix_str =
format!("\n{}", indentation_prefix.as_deref().unwrap_or(" "));

for comment in find_comments(decor.prefix()).chain(find_comments(decor.suffix())) {
match comment.comment_type {
Expand All @@ -1306,7 +1302,7 @@ fn reformat_array_multiline(deps: &mut Array) {
match comment.comment_type {
CommentType::OwnLine => {
let indentation_prefix_str =
format!("\n{}", indentation_prefix.as_ref().unwrap());
format!("\n{}", indentation_prefix.as_deref().unwrap_or(" "));
rv.push_str(&indentation_prefix_str);
}
CommentType::EndOfLine => {
Expand Down
61 changes: 61 additions & 0 deletions crates/uv/tests/it/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9024,3 +9024,64 @@ fn remove_requirement() -> Result<()> {

Ok(())
}

/// Remove all dependencies with remaining comments
#[test]
fn remove_all_with_comments() -> 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 = [
"duct",
"minilog",
# foo
# bar
]

[build-system]
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"
"#})?;

uv_snapshot!(context.filters(), context.remove().arg("duct").arg("minilog"), @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 = [
# foo
# bar
]

[build-system]
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"
"###
);
});

Ok(())
}
Loading