Discard forks when using `--upgrade` (#5905)

Fixes #5817

Needs https://github.com/astral-sh/packse/pull/213 for the test to pass.
This commit is contained in:
konsti 2024-08-09 11:13:38 +02:00 committed by GitHub
parent 1e6b021506
commit eed23be1bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 47 additions and 6 deletions

View File

@ -420,8 +420,12 @@ async fn do_lock(
// "preferences-dependent-forking" packse scenario). To avoid this, we store the forks in the // "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 // 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. // the environment changed, e.g. the python bound check above can lead to different forking.
let resolver_markers = let resolver_markers = ResolverMarkers::universal(if upgrade.is_all() {
ResolverMarkers::universal(existing_lock.and_then(|lock| lock.fork_markers().clone())); // 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()) { let resolution = match existing_lock.filter(|_| upgrade.is_none()) {
None => None, None => None,

View File

@ -1,11 +1,13 @@
#![cfg(all(feature = "python", feature = "pypi"))] #![cfg(all(feature = "python", feature = "pypi"))]
use anyhow::Result; use anyhow::Result;
use assert_cmd::assert::OutputAssertExt;
use assert_fs::prelude::*; use assert_fs::prelude::*;
use indoc::{formatdoc, indoc}; use indoc::{formatdoc, indoc};
use insta::assert_snapshot; use insta::assert_snapshot;
use url::Url; use url::Url;
use crate::common::packse_index_url;
use common::{uv_snapshot, TestContext}; use common::{uv_snapshot, TestContext};
mod common; mod common;
@ -2208,10 +2210,6 @@ fn lock_upgrade_log_multi_version() -> Result<()> {
lock, @r###" lock, @r###"
version = 1 version = 1
requires-python = ">=3.12" requires-python = ">=3.12"
environment-markers = [
"sys_platform == 'win32'",
"sys_platform != 'win32'",
]
[options] [options]
exclude-newer = "2024-03-25 00:00:00 UTC" exclude-newer = "2024-03-25 00:00:00 UTC"
@ -5804,3 +5802,42 @@ fn lock_upgrade_package() -> Result<()> {
Ok(()) 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(())
}