mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-24 05:35:04 +00:00
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 https://github.com/astral-sh/uv/issues/9533#issuecomment-2508908591.
This commit is contained in:
parent
53fe301b1d
commit
22fd9f7ff1
2 changed files with 97 additions and 2 deletions
|
@ -3,7 +3,7 @@ use petgraph::Graph;
|
|||
use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet};
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::collections::{BTreeMap, VecDeque};
|
||||
|
||||
use std::slice;
|
||||
use uv_configuration::{BuildOptions, DevGroupsManifest, ExtrasSpecification, InstallOptions};
|
||||
use uv_distribution_types::{Edge, Node, Resolution, ResolvedDist};
|
||||
use uv_normalize::{ExtraName, GroupName, PackageName, DEV_DEPENDENCIES};
|
||||
|
@ -359,7 +359,10 @@ impl<'env> InstallTarget<'env> {
|
|||
Either::Right(package.dependencies.iter())
|
||||
};
|
||||
for dep in deps {
|
||||
if !dep.complexified_marker.evaluate(marker_env, &[]) {
|
||||
if !dep
|
||||
.complexified_marker
|
||||
.evaluate(marker_env, extra.map(slice::from_ref).unwrap_or_default())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -3201,3 +3201,95 @@ fn run_with_not_existing_env_file() -> Result<()> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_with_extra_conflict() -> Result<()> {
|
||||
let context = TestContext::new("3.12");
|
||||
|
||||
let pyproject_toml = context.temp_dir.child("pyproject.toml");
|
||||
pyproject_toml.write_str(indoc! { r#"
|
||||
[project]
|
||||
name = "project"
|
||||
version = "0.1.0"
|
||||
requires-python = ">=3.12.0"
|
||||
dependencies = []
|
||||
|
||||
[project.optional-dependencies]
|
||||
foo = ["iniconfig==2.0.0"]
|
||||
bar = ["iniconfig==1.1.1"]
|
||||
|
||||
[tool.uv]
|
||||
conflicts = [
|
||||
[
|
||||
{ extra = "foo" },
|
||||
{ extra = "bar" },
|
||||
],
|
||||
]
|
||||
"#
|
||||
})?;
|
||||
|
||||
uv_snapshot!(context.filters(), context.run()
|
||||
.arg("--extra")
|
||||
.arg("foo")
|
||||
.arg("python")
|
||||
.arg("-c")
|
||||
.arg("import iniconfig"), @r###"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
Resolved 3 packages in [TIME]
|
||||
Prepared 1 package in [TIME]
|
||||
Installed 1 package in [TIME]
|
||||
+ iniconfig==2.0.0
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_with_group_conflict() -> Result<()> {
|
||||
let context = TestContext::new("3.12");
|
||||
|
||||
let pyproject_toml = context.temp_dir.child("pyproject.toml");
|
||||
pyproject_toml.write_str(indoc! { r#"
|
||||
[project]
|
||||
name = "project"
|
||||
version = "0.1.0"
|
||||
requires-python = ">=3.12.0"
|
||||
dependencies = []
|
||||
|
||||
[dependency-groups]
|
||||
foo = ["iniconfig==2.0.0"]
|
||||
bar = ["iniconfig==1.1.1"]
|
||||
|
||||
[tool.uv]
|
||||
conflicts = [
|
||||
[
|
||||
{ group = "foo" },
|
||||
{ group = "bar" },
|
||||
],
|
||||
]
|
||||
"#
|
||||
})?;
|
||||
|
||||
uv_snapshot!(context.filters(), context.run()
|
||||
.arg("--group")
|
||||
.arg("foo")
|
||||
.arg("python")
|
||||
.arg("-c")
|
||||
.arg("import iniconfig"), @r###"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
Resolved 3 packages in [TIME]
|
||||
Prepared 1 package in [TIME]
|
||||
Installed 1 package in [TIME]
|
||||
+ iniconfig==2.0.0
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue