Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Resolution type to retain dependency graph #9106

Merged
merged 2 commits into from
Nov 14, 2024
Merged

Conversation

charliermarsh
Copy link
Member

Summary

This PR should not contain any user-visible changes, but the goal is to refactor the Resolution type to retain a dependency graph. We want to be able to explain why a given package was excluded on error (see: #8962), which in turn requires that at install time, we can go back and figure out the dependency chain. At present, Resolution is just a map from package name to distribution; this PR remodels it as a graph in which each node is a package, and the edges contain markers plus extras or dependency groups.

@charliermarsh charliermarsh added the internal A refactor or improvement that is not user-facing label Nov 14, 2024
@charliermarsh charliermarsh marked this pull request as ready for review November 14, 2024 00:16
@charliermarsh charliermarsh force-pushed the charlie/graph branch 6 times, most recently from 5d17f84 to a20e24d Compare November 14, 2024 00:23
Copy link
Member

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This overall LGTM.

@@ -166,15 +172,48 @@ impl Diagnostic for ResolutionDiagnostic {
}
}

/// A node in the resolution, along with whether its been filtered out.
///
/// This is similar to [`ResolutionGraph`], but represents a resolution for a single platform.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "single platform" correct here? I think it might be, "subset of all marker environments" instead.

Although, this is also for a Node... Should this be moved to the docs for Resolution?

crates/uv-resolver/src/lock/target.rs Outdated Show resolved Hide resolved
crates/uv-resolver/src/resolution/output.rs Outdated Show resolved Hide resolved
/// dropping any extras and dependency groups from the graph nodes. Instead, each package is
/// collapsed into a single node, with extras and dependency groups annotating the _edges_, rather
/// than being represented as separate nodes. This is a more natural representation, but a further
/// departure from the PubGrub model.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very helpful! Thank you!

/// departure from the PubGrub model.
///
/// For simplicity, this transformation makes the assumption that the resolution only applies to a
/// single platform, i.e., it shouldn't be called on universal resolutions.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same "single platform" phrasing here... should it also be "subset of all marker environments"? But the last "shouldn't be called" part suggests maybe not...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if "single platform" is right, should we have an assertion like assert!(output.fork_markers.is_empty()) to enforce this?

use uv_pypi_types::{HashDigest, RequirementSource};

use crate::{BuiltDist, Diagnostic, Dist, Name, ResolvedDist, SourceDist};

/// A set of packages pinned at specific versions.
#[derive(Debug, Default, Clone)]
pub struct Resolution {
packages: BTreeMap<PackageName, ResolvedDist>,
hashes: BTreeMap<PackageName, Vec<HashDigest>>,
graph: Graph<Node, Edge, Directed>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Node, Edge, Directed sounds like they are generic types from petgraph itself.

crates/uv-resolver/src/lock/target.rs Outdated Show resolved Hide resolved
crates/uv-resolver/src/lock/target.rs Outdated Show resolved Hide resolved

// Add an edge from the root.
let index = inverse[&dist.id];
petgraph.add_edge(root, index, Edge::Prod(MarkerTree::TRUE));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really that we don't have orphan nodes anymore, but aren't those a bit different in that they aren't mandatory, but depend on the user selection? (This may just be a documentation issue)

crates/uv-resolver/src/lock/target.rs Outdated Show resolved Hide resolved
Base automatically changed from charlie/out to main November 14, 2024 14:51
@charliermarsh
Copy link
Member Author

Thank you both!

@charliermarsh charliermarsh enabled auto-merge (squash) November 14, 2024 20:09
@charliermarsh charliermarsh merged commit a552f74 into main Nov 14, 2024
61 of 64 checks passed
@charliermarsh charliermarsh deleted the charlie/graph branch November 14, 2024 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal A refactor or improvement that is not user-facing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants