Skip to content

Commit

Permalink
Reinstall package when editable label is removed (#3219)
Browse files Browse the repository at this point in the history
## Summary

Closes #3200.
  • Loading branch information
charliermarsh authored Apr 23, 2024
1 parent 2c52111 commit 697d821
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/uv-installer/src/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ fn installed_satisfies_requirement(
// If the requirement comes from a direct URL, check by URL.
Some(VersionOrUrl::Url(url)) => {
if let InstalledDist::Url(installed) = &distribution {
if &installed.url == url.raw() {
if !installed.editable && &installed.url == url.raw() {
// If the requirement came from a local path, check freshness.
if let Some(archive) = (url.scheme() == "file")
.then(|| url.to_file_path().ok())
Expand Down
8 changes: 8 additions & 0 deletions crates/uv-installer/src/site_packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ impl<'a> SitePackages<'a> {
return Ok(false);
};

if installed.editable {
return Ok(false);
}

if &installed.url != url.raw() {
return Ok(false);
}
Expand Down Expand Up @@ -438,6 +442,10 @@ impl<'a> SitePackages<'a> {
return Ok(false);
};

if installed.editable {
return Ok(false);
}

if &installed.url != url.raw() {
return Ok(false);
}
Expand Down
80 changes: 80 additions & 0 deletions crates/uv/tests/pip_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2376,6 +2376,86 @@ fn sync_editable_and_registry() -> Result<()> {
Ok(())
}

#[test]
fn sync_editable_and_local() -> Result<()> {
let context = TestContext::new("3.12");

// Copy the black test editable into the "current" directory
copy_dir_all(
context
.workspace_root
.join("scripts/packages/black_editable"),
context.temp_dir.join("black_editable"),
)?;

// Install the editable version of Black.
let requirements_txt = context.temp_dir.child("requirements.txt");
requirements_txt.write_str(indoc::indoc! {r"
-e file:./black_editable
"
})?;

uv_snapshot!(context.filters(), command(&context)
.arg(requirements_txt.path()), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Built 1 editable in [TIME]
Installed 1 package in [TIME]
+ black==0.1.0 (from file://[TEMP_DIR]/black_editable)
"###
);

// Install the non-editable version of Black. This should replace the editable version.
let requirements_txt = context.temp_dir.child("requirements.txt");
requirements_txt.write_str(indoc::indoc! {r"
black @ file:./black_editable
"
})?;

uv_snapshot!(context.filters(), command(&context)
.arg(requirements_txt.path()), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 1 package in [TIME]
Downloaded 1 package in [TIME]
Uninstalled 1 package in [TIME]
Installed 1 package in [TIME]
- black==0.1.0 (from file://[TEMP_DIR]/black_editable)
+ black==0.1.0 (from file://[TEMP_DIR]/black_editable)
"###
);

// Reinstall the editable version of Black. This should replace the non-editable version.
let requirements_txt = context.temp_dir.child("requirements.txt");
requirements_txt.write_str(indoc::indoc! {r"
-e file:./black_editable
"
})?;

uv_snapshot!(context.filters(), command(&context)
.arg(requirements_txt.path()), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Built 1 editable in [TIME]
Uninstalled 1 package in [TIME]
Installed 1 package in [TIME]
- black==0.1.0 (from file://[TEMP_DIR]/black_editable)
+ black==0.1.0 (from file://[TEMP_DIR]/black_editable)
"###
);

Ok(())
}

#[test]
fn incompatible_wheel() -> Result<()> {
let context = TestContext::new("3.12");
Expand Down

0 comments on commit 697d821

Please sign in to comment.