Skip to content

Commit eed23be

Browse files
authored
Discard forks when using --upgrade (#5905)
Fixes #5817 Needs astral-sh/packse#213 for the test to pass.
1 parent 1e6b021 commit eed23be

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

crates/uv/src/commands/project/lock.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,12 @@ async fn do_lock(
420420
// "preferences-dependent-forking" packse scenario). To avoid this, we store the forks in the
421421
// lockfile. We read those after all the lockfile filters, to allow the forks to change when
422422
// the environment changed, e.g. the python bound check above can lead to different forking.
423-
let resolver_markers =
424-
ResolverMarkers::universal(existing_lock.and_then(|lock| lock.fork_markers().clone()));
423+
let resolver_markers = ResolverMarkers::universal(if upgrade.is_all() {
424+
// We're discarding all preferences, so we're also discarding the existing forks.
425+
None
426+
} else {
427+
existing_lock.and_then(|lock| lock.fork_markers().clone())
428+
});
425429

426430
let resolution = match existing_lock.filter(|_| upgrade.is_none()) {
427431
None => None,

crates/uv/tests/lock.rs

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#![cfg(all(feature = "python", feature = "pypi"))]
22

33
use anyhow::Result;
4+
use assert_cmd::assert::OutputAssertExt;
45
use assert_fs::prelude::*;
56
use indoc::{formatdoc, indoc};
67
use insta::assert_snapshot;
78
use url::Url;
89

10+
use crate::common::packse_index_url;
911
use common::{uv_snapshot, TestContext};
1012

1113
mod common;
@@ -2208,10 +2210,6 @@ fn lock_upgrade_log_multi_version() -> Result<()> {
22082210
lock, @r###"
22092211
version = 1
22102212
requires-python = ">=3.12"
2211-
environment-markers = [
2212-
"sys_platform == 'win32'",
2213-
"sys_platform != 'win32'",
2214-
]
22152213
22162214
[options]
22172215
exclude-newer = "2024-03-25 00:00:00 UTC"
@@ -5804,3 +5802,42 @@ fn lock_upgrade_package() -> Result<()> {
58045802

58055803
Ok(())
58065804
}
5805+
5806+
/// Check that we discard the fork marker from the lockfile when using `--upgrade`.
5807+
#[test]
5808+
fn lock_upgrade_drop_fork_markers() -> Result<()> {
5809+
let context = TestContext::new("3.12");
5810+
5811+
let requirements = r#"[project]
5812+
name = "forking"
5813+
version = "0.1.0"
5814+
requires-python = ">=3.12"
5815+
dependencies = ["fork-upgrade-foo==1"]
5816+
"#;
5817+
5818+
let pyproject_toml = context.temp_dir.child("pyproject.toml");
5819+
pyproject_toml.write_str(requirements)?;
5820+
context
5821+
.lock()
5822+
.arg("--index-url")
5823+
.arg(packse_index_url())
5824+
.env_remove("UV_EXCLUDE_NEWER")
5825+
.assert()
5826+
.success();
5827+
let lock = fs_err::read_to_string(context.temp_dir.join("uv.lock")).unwrap();
5828+
assert!(lock.contains("environment-markers"));
5829+
5830+
// Remove the bound and lock with `--upgrade`.
5831+
pyproject_toml.write_str(&requirements.replace("fork-upgrade-foo==1", "fork-upgrade-foo"))?;
5832+
context
5833+
.lock()
5834+
.arg("--index-url")
5835+
.arg(packse_index_url())
5836+
.env_remove("UV_EXCLUDE_NEWER")
5837+
.arg("--upgrade")
5838+
.assert()
5839+
.success();
5840+
let lock = fs_err::read_to_string(context.temp_dir.join("uv.lock")).unwrap();
5841+
assert!(!lock.contains("environment-markers"));
5842+
Ok(())
5843+
}

0 commit comments

Comments
 (0)