diff --git a/crates/distribution-types/src/lib.rs b/crates/distribution-types/src/lib.rs index 95ca6c9125fb..64383ae53162 100644 --- a/crates/distribution-types/src/lib.rs +++ b/crates/distribution-types/src/lib.rs @@ -371,6 +371,13 @@ impl Dist { } } + pub fn index(&self) -> Option { + match self { + Self::Built(dist) => dist.index(), + Self::Source(dist) => dist.index(), + } + } + /// Returns the [`File`] instance, if this dist is from a registry with simple json api support pub fn file(&self) -> Option<&File> { match self { @@ -388,6 +395,14 @@ impl Dist { } impl BuiltDist { + pub fn index(&self) -> Option { + match self { + Self::Registry(registry) => Some(registry.index.to_string()), + Self::DirectUrl(_) => None, + Self::Path(_) => None, + } + } + /// Returns the [`File`] instance, if this dist is from a registry with simple json api support pub fn file(&self) -> Option<&File> { match self { @@ -406,6 +421,13 @@ impl BuiltDist { } impl SourceDist { + pub fn index(&self) -> Option { + match self { + Self::Registry(registry) => Some(registry.index.to_string()), + Self::DirectUrl(_) | Self::Git(_) | Self::Path(_) => None, + } + } + /// Returns the [`File`] instance, if this dist is from a registry with simple json api support pub fn file(&self) -> Option<&File> { match self { diff --git a/crates/distribution-types/src/resolved.rs b/crates/distribution-types/src/resolved.rs index 91015e4f389d..8e5260a06eb1 100644 --- a/crates/distribution-types/src/resolved.rs +++ b/crates/distribution-types/src/resolved.rs @@ -31,6 +31,13 @@ impl ResolvedDist { Self::Installed(dist) => dist.is_editable(), } } + + pub fn index(&self) -> Option { + match self { + Self::Installable(dist) => dist.index(), + Self::Installed(_) => None, + } + } } impl ResolvedDistRef<'_> { diff --git a/crates/uv-resolver/src/resolution.rs b/crates/uv-resolver/src/resolution.rs index c3e0dcb849d8..5494f04223d2 100644 --- a/crates/uv-resolver/src/resolution.rs +++ b/crates/uv-resolver/src/resolution.rs @@ -576,6 +576,13 @@ impl<'a> Node<'a> { Node::Distribution(name, _, _) => NodeKey::Distribution(name), } } + + fn index(&self) -> Option { + match self { + Node::Editable(_, _) => None, + Node::Distribution(_, dist, _) => dist.index(), + } + } } impl Verbatim for Node<'_> { @@ -672,6 +679,12 @@ impl std::fmt::Display for DisplayResolutionGraph<'_> { .collect::>(); edges.sort_unstable_by_key(|package| package.name()); + let index = node.index(); + let index_line = if index.is_some() { + format!("\n # from {}", index.unwrap()) + } else { + "".to_string() + }; match self.annotation_style { AnnotationStyle::Line => { if !edges.is_empty() { @@ -681,7 +694,7 @@ impl std::fmt::Display for DisplayResolutionGraph<'_> { .map(|dependency| dependency.name().to_string()) .collect::>() .join(", "); - let comment = format!("# via {deps}").green().to_string(); + let comment = format!("# via {deps}{index_line}").green().to_string(); annotation = Some((separator, comment)); } } @@ -689,7 +702,9 @@ impl std::fmt::Display for DisplayResolutionGraph<'_> { [] => {} [edge] => { let separator = "\n"; - let comment = format!(" # via {}", edge.name()).green().to_string(); + let comment = format!(" # via {}{index_line}", edge.name()) + .green() + .to_string(); annotation = Some((separator, comment)); } edges => { @@ -699,7 +714,8 @@ impl std::fmt::Display for DisplayResolutionGraph<'_> { .map(|dependency| format!(" # {}", dependency.name())) .collect::>() .join("\n"); - let comment = format!(" # via\n{deps}").green().to_string(); + let comment = + format!(" # via\n{deps}{index_line}").green().to_string(); annotation = Some((separator, comment)); } },