Skip to content

Commit 22fd9f7

Browse files
Pass extra when evaluating lockfile markers (#9539)
## Summary When we serialize and deserialize the lockfile, we remove the conflict markers. So in the linked case, the edges for the `tqdm` entries are like: ``` complexified_marker: UniversalMarker { pep508_marker: python_full_version >= '3.9.0', conflict_marker: true, }, ``` However... when we evaluate in-memory, the conflict markers are still there... ``` complexified_marker: UniversalMarker { pep508_marker: true, conflict_marker: extra == 't1' and extra != 't2', }, ``` So if `uv run` creates the lockfile, we evaluate this as `false`. We should make this consistent, and I expect @BurntSushi is aware. But for now, it's reasonable / correct to pass the extra when evaluating at this specific point, since we know the dependency was enabled by the marker. Closes #9533 (comment).
1 parent 53fe301 commit 22fd9f7

File tree

2 files changed

+97
-2
lines changed

2 files changed

+97
-2
lines changed

crates/uv-resolver/src/lock/target.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use petgraph::Graph;
33
use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet};
44
use std::collections::hash_map::Entry;
55
use std::collections::{BTreeMap, VecDeque};
6-
6+
use std::slice;
77
use uv_configuration::{BuildOptions, DevGroupsManifest, ExtrasSpecification, InstallOptions};
88
use uv_distribution_types::{Edge, Node, Resolution, ResolvedDist};
99
use uv_normalize::{ExtraName, GroupName, PackageName, DEV_DEPENDENCIES};
@@ -359,7 +359,10 @@ impl<'env> InstallTarget<'env> {
359359
Either::Right(package.dependencies.iter())
360360
};
361361
for dep in deps {
362-
if !dep.complexified_marker.evaluate(marker_env, &[]) {
362+
if !dep
363+
.complexified_marker
364+
.evaluate(marker_env, extra.map(slice::from_ref).unwrap_or_default())
365+
{
363366
continue;
364367
}
365368

crates/uv/tests/it/run.rs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3201,3 +3201,95 @@ fn run_with_not_existing_env_file() -> Result<()> {
32013201

32023202
Ok(())
32033203
}
3204+
3205+
#[test]
3206+
fn run_with_extra_conflict() -> Result<()> {
3207+
let context = TestContext::new("3.12");
3208+
3209+
let pyproject_toml = context.temp_dir.child("pyproject.toml");
3210+
pyproject_toml.write_str(indoc! { r#"
3211+
[project]
3212+
name = "project"
3213+
version = "0.1.0"
3214+
requires-python = ">=3.12.0"
3215+
dependencies = []
3216+
3217+
[project.optional-dependencies]
3218+
foo = ["iniconfig==2.0.0"]
3219+
bar = ["iniconfig==1.1.1"]
3220+
3221+
[tool.uv]
3222+
conflicts = [
3223+
[
3224+
{ extra = "foo" },
3225+
{ extra = "bar" },
3226+
],
3227+
]
3228+
"#
3229+
})?;
3230+
3231+
uv_snapshot!(context.filters(), context.run()
3232+
.arg("--extra")
3233+
.arg("foo")
3234+
.arg("python")
3235+
.arg("-c")
3236+
.arg("import iniconfig"), @r###"
3237+
success: true
3238+
exit_code: 0
3239+
----- stdout -----
3240+
3241+
----- stderr -----
3242+
Resolved 3 packages in [TIME]
3243+
Prepared 1 package in [TIME]
3244+
Installed 1 package in [TIME]
3245+
+ iniconfig==2.0.0
3246+
"###);
3247+
3248+
Ok(())
3249+
}
3250+
3251+
#[test]
3252+
fn run_with_group_conflict() -> Result<()> {
3253+
let context = TestContext::new("3.12");
3254+
3255+
let pyproject_toml = context.temp_dir.child("pyproject.toml");
3256+
pyproject_toml.write_str(indoc! { r#"
3257+
[project]
3258+
name = "project"
3259+
version = "0.1.0"
3260+
requires-python = ">=3.12.0"
3261+
dependencies = []
3262+
3263+
[dependency-groups]
3264+
foo = ["iniconfig==2.0.0"]
3265+
bar = ["iniconfig==1.1.1"]
3266+
3267+
[tool.uv]
3268+
conflicts = [
3269+
[
3270+
{ group = "foo" },
3271+
{ group = "bar" },
3272+
],
3273+
]
3274+
"#
3275+
})?;
3276+
3277+
uv_snapshot!(context.filters(), context.run()
3278+
.arg("--group")
3279+
.arg("foo")
3280+
.arg("python")
3281+
.arg("-c")
3282+
.arg("import iniconfig"), @r###"
3283+
success: true
3284+
exit_code: 0
3285+
----- stdout -----
3286+
3287+
----- stderr -----
3288+
Resolved 3 packages in [TIME]
3289+
Prepared 1 package in [TIME]
3290+
Installed 1 package in [TIME]
3291+
+ iniconfig==2.0.0
3292+
"###);
3293+
3294+
Ok(())
3295+
}

0 commit comments

Comments
 (0)