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

Avoid updating pyproject.toml offsets on non-add edits #7262

Merged
merged 1 commit into from
Sep 10, 2024
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
25 changes: 12 additions & 13 deletions crates/uv/src/commands/project/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,21 +411,20 @@ pub(crate) async fn add(
}
};

// Keep track of the exact location of the edit.
let index = edit.index();

// If the edit was inserted before the end of the list, update the existing edits.
for edit in &mut edits {
if *edit.dependency_type == dependency_type {
match &mut edit.edit {
ArrayEdit::Add(existing) => {
if *existing >= index {
*existing += 1;
if let ArrayEdit::Add(index) = &edit {
for edit in &mut edits {
if *edit.dependency_type == dependency_type {
match &mut edit.edit {
ArrayEdit::Add(existing) => {
if *existing >= *index {
*existing += 1;
}
}
}
ArrayEdit::Update(existing) => {
if *existing >= index {
*existing += 1;
ArrayEdit::Update(existing) => {
if *existing >= *index {
*existing += 1;
}
}
}
}
Expand Down
50 changes: 50 additions & 0 deletions crates/uv/tests/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4539,3 +4539,53 @@ fn custom_dependencies() -> Result<()> {
});
Ok(())
}

/// Regression test for: <https://github.com/astral-sh/uv/issues/7259>
#[test]
fn update_offset() -> 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 = [
"iniconfig",
]
"#})?;

uv_snapshot!(context.filters(), context.add().args(["typing-extensions", "iniconfig"]), @r###"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Resolved 3 packages in [TIME]
Prepared 2 packages in [TIME]
Installed 2 packages in [TIME]
+ iniconfig==2.0.0
+ typing-extensions==4.10.0
"###);

let pyproject_toml = fs_err::read_to_string(context.temp_dir.join("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 = [
"iniconfig",
"typing-extensions>=4.10.0",
]
"###
);
});
Ok(())
}
Loading