Skip to content

Commit

Permalink
Only remove a source from [tool.uv.sources] if it is no long being …
Browse files Browse the repository at this point in the history
…referenced (astral-sh#8366)

## Summary

Resolves astral-sh#8361
  • Loading branch information
j178 authored Oct 19, 2024
1 parent ca55793 commit e980c1b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
5 changes: 5 additions & 0 deletions crates/uv-workspace/src/pyproject_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,11 @@ impl PyProjectTomlMut {

/// Remove a matching source from `tool.uv.sources`, if it exists.
fn remove_source(&mut self, name: &PackageName) -> Result<(), Error> {
// If the dependency is still in use, don't remove the source.
if !self.find_dependency(name, None).is_empty() {
return Ok(());
}

if let Some(sources) = self
.doc
.get_mut("tool")
Expand Down
26 changes: 14 additions & 12 deletions crates/uv/tests/it/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4584,12 +4584,10 @@ fn remove_repeated() -> Result<()> {
----- stdout -----
----- stderr -----
Resolved 4 packages in [TIME]
Prepared 3 packages in [TIME]
Installed 3 packages in [TIME]
+ anyio==4.3.0
+ idna==3.6
+ sniffio==1.3.1
Resolved 2 packages in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
+ anyio==4.3.0+foo (from file://[WORKSPACE]/scripts/packages/anyio_local)
"###);

let pyproject_toml = context.read("pyproject.toml");
Expand All @@ -4610,6 +4608,9 @@ fn remove_repeated() -> Result<()> {
[tool.uv]
dev-dependencies = ["anyio"]
[tool.uv.sources]
anyio = { path = "[WORKSPACE]/scripts/packages/anyio_local" }
"###
);
});
Expand All @@ -4620,8 +4621,8 @@ fn remove_repeated() -> Result<()> {
----- stdout -----
----- stderr -----
Resolved 4 packages in [TIME]
Audited 3 packages in [TIME]
Resolved 2 packages in [TIME]
Audited 1 package in [TIME]
"###);

let pyproject_toml = context.read("pyproject.toml");
Expand All @@ -4642,6 +4643,9 @@ fn remove_repeated() -> Result<()> {
[tool.uv]
dev-dependencies = ["anyio"]
[tool.uv.sources]
anyio = { path = "[WORKSPACE]/scripts/packages/anyio_local" }
"###
);
});
Expand All @@ -4653,10 +4657,8 @@ fn remove_repeated() -> Result<()> {
----- stderr -----
Resolved 1 package in [TIME]
Uninstalled 3 packages in [TIME]
- anyio==4.3.0
- idna==3.6
- sniffio==1.3.1
Uninstalled 1 package in [TIME]
- anyio==4.3.0+foo (from file://[WORKSPACE]/scripts/packages/anyio_local)
"###);

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

0 comments on commit e980c1b

Please sign in to comment.