Skip to content

Commit

Permalink
Use IndexUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Apr 10, 2024
1 parent 2c50f89 commit 5c02973
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
15 changes: 9 additions & 6 deletions crates/distribution-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ impl Dist {
}
}

pub fn index(&self) -> Option<String> {
/// Returns the [`IndexUrl`], if the distribution is from a registry.
pub fn index(&self) -> Option<&IndexUrl> {
match self {
Self::Built(dist) => dist.index(),
Self::Source(dist) => dist.index(),
Expand All @@ -395,15 +396,16 @@ impl Dist {
}

impl BuiltDist {
pub fn index(&self) -> Option<String> {
/// Returns the [`IndexUrl`], if the distribution is from a registry.
pub fn index(&self) -> Option<&IndexUrl> {
match self {
Self::Registry(registry) => Some(registry.index.to_string()),
Self::Registry(registry) => Some(&registry.index),
Self::DirectUrl(_) => None,
Self::Path(_) => None,
}
}

/// Returns the [`File`] instance, if this dist is from a registry with simple json api support
/// Returns the [`File`] instance, if this distribution is from a registry.
pub fn file(&self) -> Option<&File> {
match self {
Self::Registry(registry) => Some(&registry.file),
Expand All @@ -421,9 +423,10 @@ impl BuiltDist {
}

impl SourceDist {
pub fn index(&self) -> Option<String> {
/// Returns the [`IndexUrl`], if the distribution is from a registry.
pub fn index(&self) -> Option<&IndexUrl> {
match self {
Self::Registry(registry) => Some(registry.index.to_string()),
Self::Registry(registry) => Some(&registry.index),
Self::DirectUrl(_) | Self::Git(_) | Self::Path(_) => None,
}
}
Expand Down
7 changes: 4 additions & 3 deletions crates/distribution-types/src/resolved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::fmt::{Display, Formatter};
use pep508_rs::PackageName;

use crate::{
Dist, DistributionId, DistributionMetadata, Identifier, InstalledDist, Name, ResourceId,
VersionOrUrl,
Dist, DistributionId, DistributionMetadata, Identifier, IndexUrl, InstalledDist, Name,
ResourceId, VersionOrUrl,
};

/// A distribution that can be used for resolution and installation.
Expand Down Expand Up @@ -32,7 +32,8 @@ impl ResolvedDist {
}
}

pub fn index(&self) -> Option<String> {
/// Returns the [`IndexUrl`], if the distribution is from a registry.
pub fn index(&self) -> Option<&IndexUrl> {
match self {
Self::Installable(dist) => dist.index(),
Self::Installed(_) => None,
Expand Down
5 changes: 3 additions & 2 deletions crates/uv-resolver/src/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use pubgrub::type_aliases::SelectedDependencies;
use rustc_hash::{FxHashMap, FxHashSet};

use distribution_types::{
Dist, DistributionMetadata, LocalEditable, Name, PackageId, ResolvedDist, Verbatim,
Dist, DistributionMetadata, IndexUrl, LocalEditable, Name, PackageId, ResolvedDist, Verbatim,
VersionOrUrl,
};
use once_map::OnceMap;
Expand Down Expand Up @@ -584,7 +584,8 @@ impl<'a> Node<'a> {
}
}

fn index(&self) -> Option<String> {
/// Return the [`IndexUrl`] of the distribution, if any.
fn index(&self) -> Option<&IndexUrl> {
match self {
Node::Editable(_, _) => None,
Node::Distribution(_, dist, _) => dist.index(),
Expand Down

0 comments on commit 5c02973

Please sign in to comment.