Skip to content

Commit

Permalink
Show non-project dependencies in uv tree (#10149)
Browse files Browse the repository at this point in the history
## Summary

Closes #10147.
  • Loading branch information
charliermarsh authored Dec 24, 2024
1 parent e09b108 commit 6745a8b
Show file tree
Hide file tree
Showing 4 changed files with 337 additions and 62 deletions.
28 changes: 19 additions & 9 deletions crates/uv-resolver/src/lock/requirements_txt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,22 @@ impl<'lock> RequirementsTxtExport<'lock> {
// (legacy) non-project workspace roots).
let root_requirements = target
.lock()
.dependency_groups()
.requirements()
.iter()
.filter_map(|(group, deps)| {
if dev.contains(group) {
Some(deps)
} else {
None
}
})
.flatten()
.chain(
target
.lock()
.dependency_groups()
.iter()
.filter_map(|(group, deps)| {
if dev.contains(group) {
Some(deps)
} else {
None
}
})
.flatten(),
)
.filter(|dep| !prune.contains(&dep.name))
.collect::<Vec<_>>();

Expand Down Expand Up @@ -185,6 +191,10 @@ impl<'lock> RequirementsTxtExport<'lock> {
combined
};

if marker.is_false() {
continue;
}

// Simplify the marker.
let marker = target.lock().simplify_environment(marker);

Expand Down
40 changes: 40 additions & 0 deletions crates/uv-resolver/src/lock/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,46 @@ impl<'env> InstallTarget<'env> {
}
}

// Add any requirements that are exclusive to the workspace root (e.g., dependencies in
// PEP 723 scripts).
for dependency in self.lock().requirements() {
if !dependency.marker.evaluate(marker_env, &[]) {
continue;
}

let root_name = &dependency.name;
let dist = self
.lock()
.find_by_markers(root_name, marker_env)
.map_err(|_| LockErrorKind::MultipleRootPackages {
name: root_name.clone(),
})?
.ok_or_else(|| LockErrorKind::MissingRootPackage {
name: root_name.clone(),
})?;

// Add the package to the graph.
let index = petgraph.add_node(if dev.prod() {
self.package_to_node(dist, tags, build_options, install_options)?
} else {
self.non_installable_node(dist, tags)?
});
inverse.insert(&dist.id, index);

// Add the edge.
petgraph.add_edge(root, index, Edge::Prod(dependency.marker));

// Push its dependencies on the queue.
if seen.insert((&dist.id, None)) {
queue.push_back((dist, None));
}
for extra in &dependency.extras {
if seen.insert((&dist.id, Some(extra))) {
queue.push_back((dist, Some(extra)));
}
}
}

// Add any dependency groups that are exclusive to the workspace root (e.g., dev
// dependencies in (legacy) non-project workspace roots).
for (group, dependency) in self
Expand Down
Loading

0 comments on commit 6745a8b

Please sign in to comment.