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
Changes from 1 commit
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
Prev Previous commit
Remove macro
  • Loading branch information
charliermarsh committed Nov 14, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 30691c91e8d27684c15b65e38f1a324d5078d860
16 changes: 8 additions & 8 deletions crates/uv-distribution-types/src/resolution.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use petgraph::{Directed, Graph};

use uv_distribution_filename::DistExtension;
use uv_normalize::{ExtraName, GroupName, PackageName};
use uv_pep508::MarkerTree;
@@ -8,23 +6,27 @@ use uv_pypi_types::{HashDigest, RequirementSource};
use crate::{BuiltDist, Diagnostic, Dist, Name, ResolvedDist, SourceDist};

/// A set of packages pinned at specific versions.
///
/// This is similar to [`ResolverOutput`], but represents a resolution for a subset of all
/// marker environments. For example, the resolution is guaranteed to contain at most one version
/// for a given package.
#[derive(Debug, Default, Clone)]
pub struct Resolution {
graph: Graph<Node, Edge, Directed>,
graph: petgraph::graph::DiGraph<Node, Edge>,
diagnostics: Vec<ResolutionDiagnostic>,
}

impl Resolution {
/// Create a new resolution from the given pinned packages.
pub fn new(graph: Graph<Node, Edge, Directed>) -> Self {
pub fn new(graph: petgraph::graph::DiGraph<Node, Edge>) -> Self {
Self {
graph,
diagnostics: Vec::new(),
}
}

/// Return the underlying graph of the resolution.
pub fn graph(&self) -> &Graph<Node, Edge, Directed> {
pub fn graph(&self) -> &petgraph::graph::DiGraph<Node, Edge> {
&self.graph
}

@@ -174,10 +176,8 @@ 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.
///
/// We retain filtered nodes as we still need to be able to trace dependencies through the graph
/// (e.g., to determine why a package was install in the resolution).
/// (e.g., to determine why a package was included in the resolution).
#[derive(Debug, Clone)]
pub enum Node {
Root,
Loading
Loading