Skip to content

Commit

Permalink
Discard forks when using --upgrade (#5905)
Browse files Browse the repository at this point in the history
Fixes #5817

Needs astral-sh/packse#213 for the test to pass.
  • Loading branch information
konstin authored and zanieb committed Aug 9, 2024
1 parent 6effbd0 commit 2ffb0a5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
8 changes: 6 additions & 2 deletions crates/uv/src/commands/project/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,12 @@ async fn do_lock(
// "preferences-dependent-forking" packse scenario). To avoid this, we store the forks in the
// lockfile. We read those after all the lockfile filters, to allow the forks to change when
// the environment changed, e.g. the python bound check above can lead to different forking.
let resolver_markers =
ResolverMarkers::universal(existing_lock.and_then(|lock| lock.fork_markers().clone()));
let resolver_markers = ResolverMarkers::universal(if upgrade.is_all() {
// We're discarding all preferences, so we're also discarding the existing forks.
None
} else {
existing_lock.and_then(|lock| lock.fork_markers().clone())
});

let resolution = match existing_lock.filter(|_| upgrade.is_none()) {
None => None,
Expand Down
45 changes: 41 additions & 4 deletions crates/uv/tests/lock.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#![cfg(all(feature = "python", feature = "pypi"))]

use anyhow::Result;
use assert_cmd::assert::OutputAssertExt;
use assert_fs::prelude::*;
use indoc::{formatdoc, indoc};
use insta::assert_snapshot;
use url::Url;

use crate::common::packse_index_url;
use common::{uv_snapshot, TestContext};

mod common;
Expand Down Expand Up @@ -2208,10 +2210,6 @@ fn lock_upgrade_log_multi_version() -> Result<()> {
lock, @r###"
version = 1
requires-python = ">=3.12"
environment-markers = [
"sys_platform == 'win32'",
"sys_platform != 'win32'",
]
[options]
exclude-newer = "2024-03-25 00:00:00 UTC"
Expand Down Expand Up @@ -5804,3 +5802,42 @@ fn lock_upgrade_package() -> Result<()> {

Ok(())
}

/// Check that we discard the fork marker from the lockfile when using `--upgrade`.
#[test]
fn lock_upgrade_drop_fork_markers() -> Result<()> {
let context = TestContext::new("3.12");

let requirements = r#"[project]
name = "forking"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["fork-upgrade-foo==1"]
"#;

let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(requirements)?;
context
.lock()
.arg("--index-url")
.arg(packse_index_url())
.env_remove("UV_EXCLUDE_NEWER")
.assert()
.success();
let lock = fs_err::read_to_string(context.temp_dir.join("uv.lock")).unwrap();
assert!(lock.contains("environment-markers"));

// Remove the bound and lock with `--upgrade`.
pyproject_toml.write_str(&requirements.replace("fork-upgrade-foo==1", "fork-upgrade-foo"))?;
context
.lock()
.arg("--index-url")
.arg(packse_index_url())
.env_remove("UV_EXCLUDE_NEWER")
.arg("--upgrade")
.assert()
.success();
let lock = fs_err::read_to_string(context.temp_dir.join("uv.lock")).unwrap();
assert!(!lock.contains("environment-markers"));
Ok(())
}

0 comments on commit 2ffb0a5

Please sign in to comment.