Visitar URL original
Preserve conditional extra markers in exports by charliermarsh · Pull Request #20148 · astral-sh/uv · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Preserve conditional extra markers in exports
  • Loading branch information
charliermarsh committed Jul 6, 2026
commit 08c1f754106883a92aa8ac2fc08e3d5a30612f7d
16 changes: 10 additions & 6 deletions crates/uv-resolver/src/lock/export/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,15 +511,19 @@ fn conflict_marker_reachability<'lock>(
parent_marker.and(marker);
}
Edge::Optional { extra, marker, .. } => {
// The optional extra is active for this edge itself, so add it before
// resolving any active extras on the edge.
if let Node::Package(parent) = graph[parent_index] {
// The optional edge is only active when its extra is active. Preserve the
// extra's reachability marker, since matching constraints can be omitted from
// the dependency marker as redundant when the lockfile is written.
let active_marker = if let Node::Package(parent) = graph[parent_index] {
let item = ConflictItem::from((parent.name().clone(), (*extra).clone()));
parent_map.insert(item, parent_marker);
}
*parent_map.entry(item).or_insert(parent_marker)
} else {
parent_marker
};

// Resolve any active extras on the edge.
let marker = resolve_activated_extras(*marker, scope_package, &parent_map);
let mut marker = resolve_activated_extras(*marker, scope_package, &parent_map);
marker.and(active_marker);

// Propagate the edge to the known conflicts.
for value in parent_map.values_mut() {
Expand Down
41 changes: 41 additions & 0 deletions crates/uv/tests/project/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,47 @@ fn requirements_txt_dependency_extra() -> Result<()> {
Ok(())
}

/// An optional dependency's marker can be omitted from the lockfile when the extra is only active
/// in environments that satisfy the same marker. Ensure export restores the extra's activation
/// marker instead of making the dependency unconditional.
#[test]
fn requirements_txt_conditional_transitive_extra() -> Result<()> {
let context = uv_test::test_context!("3.12").with_exclude_newer("2026-05-12T00:00:00Z");

let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
r#"
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.10"
dependencies = ["urllib3==2.7.0"]

[project.optional-dependencies]
zstd = ["urllib3[zstd]==2.7.0 ; python_full_version < '3.14'"]
"#,
)?;

context.lock().assert().success();

uv_snapshot!(context.filters(), context.export().arg("--all-extras").arg("--no-hashes"), @r"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv export --cache-dir [CACHE_DIR] --all-extras --no-hashes
backports-zstd==1.5.0 ; python_full_version < '3.14'
# via urllib3
urllib3==2.7.0
# via project

----- stderr -----
Resolved 3 packages in [TIME]
");

Ok(())
}

#[test]
fn requirements_txt_project_extra() -> Result<()> {
let context = uv_test::test_context!("3.12");
Expand Down
Loading