Skip to content

Commit

Permalink
Always accept already-installed pre-releases (#5419)
Browse files Browse the repository at this point in the history
## Summary

If a pre-release is already installed, we should allow it to be used
even if it doesn't match the strategy.

Closes #5418.
  • Loading branch information
charliermarsh authored Jul 24, 2024
1 parent 7bcafec commit fff3a7d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 16 deletions.
24 changes: 8 additions & 16 deletions crates/uv-resolver/src/candidate_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,6 @@ impl CandidateSelector {
break 'preference;
}

// Respect the pre-release strategy for this fork.
if version.any_prerelease()
&& self.prerelease_strategy.allows(package_name, markers)
!= AllowPreRelease::Yes
{
break 'preference;
}

// Check for a locally installed distribution that matches the preferred version
if !exclusions.contains(package_name) {
let installed_dists = installed_packages.get_packages(package_name);
Expand Down Expand Up @@ -155,6 +147,14 @@ impl CandidateSelector {
}
}

// Respect the pre-release strategy for this fork.
if version.any_prerelease()
&& self.prerelease_strategy.allows(package_name, markers)
!= AllowPreRelease::Yes
{
break 'preference;
}

// Check for a remote distribution that matches the preferred version
if let Some(file) = version_maps
.iter()
Expand Down Expand Up @@ -183,14 +183,6 @@ impl CandidateSelector {
return None;
}

// Respect the pre-release strategy for this fork.
if version.any_prerelease()
&& self.prerelease_strategy.allows(package_name, markers)
!= AllowPreRelease::Yes
{
return None;
}

debug!("Found installed version of {dist} that satisfies {range}");
return Some(Candidate {
name: package_name,
Expand Down
43 changes: 43 additions & 0 deletions crates/uv/tests/pip_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6105,3 +6105,46 @@ fn local_index_fallback() -> Result<()> {

Ok(())
}

#[test]
fn accept_existing_prerelease() -> Result<()> {
let context = TestContext::new("3.12").with_filtered_counts();
let requirements_txt = context.temp_dir.child("requirements.txt");
requirements_txt.write_str("Flask==2.0.0rc1")?;

// Install a pre-release version of `flask`.
uv_snapshot!(context.filters(), context.pip_install().arg("Flask==2.0.0rc1"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved [N] packages in [TIME]
Prepared [N] packages in [TIME]
Installed [N] packages in [TIME]
+ click==8.1.7
+ flask==2.0.0rc1
+ itsdangerous==2.1.2
+ jinja2==3.1.3
+ markupsafe==2.1.5
+ werkzeug==3.0.1
"###
);

// Install `flask-login`, without enabling pre-releases. The existing version of `flask` should
// still be accepted.
uv_snapshot!(context.filters(), context.pip_install().arg("flask-login==0.6.0"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved [N] packages in [TIME]
Prepared [N] packages in [TIME]
Installed [N] packages in [TIME]
+ flask-login==0.6.0
"###
);

Ok(())
}

0 comments on commit fff3a7d

Please sign in to comment.