From eed23be1bd690e95c642714a5d7728cec81f7309 Mon Sep 17 00:00:00 2001 From: konsti Date: Fri, 9 Aug 2024 11:13:38 +0200 Subject: [PATCH] Discard forks when using `--upgrade` (#5905) Fixes #5817 Needs https://github.com/astral-sh/packse/pull/213 for the test to pass. --- crates/uv/src/commands/project/lock.rs | 8 +++-- crates/uv/tests/lock.rs | 45 +++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/crates/uv/src/commands/project/lock.rs b/crates/uv/src/commands/project/lock.rs index 9efcde180..5514b3823 100644 --- a/crates/uv/src/commands/project/lock.rs +++ b/crates/uv/src/commands/project/lock.rs @@ -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, diff --git a/crates/uv/tests/lock.rs b/crates/uv/tests/lock.rs index 7b05b5de4..a3d1bab05 100644 --- a/crates/uv/tests/lock.rs +++ b/crates/uv/tests/lock.rs @@ -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; @@ -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" @@ -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(()) +}