Skip to content

Commit

Permalink
Make version an optional field on installable distribution type
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jan 15, 2025
1 parent 9e06aa8 commit bb87ef8
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 62 deletions.
6 changes: 3 additions & 3 deletions crates/uv-distribution-types/src/dist_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl DerivationChain {
dist.name().clone(),
extra.clone(),
group.clone(),
dist.version().clone(),
dist.version().cloned(),
Ranges::empty(),
));
let target = edge.source();
Expand Down Expand Up @@ -191,7 +191,7 @@ pub struct DerivationStep {
/// The enabled dependency group of the package, if any.
pub group: Option<GroupName>,
/// The version of the package.
pub version: Version,
pub version: Option<Version>,
/// The constraints applied to the subsequent package in the chain.
pub range: Ranges<Version>,
}
Expand All @@ -202,7 +202,7 @@ impl DerivationStep {
name: PackageName,
extra: Option<ExtraName>,
group: Option<GroupName>,
version: Version,
version: Option<Version>,
range: Ranges<Version>,
) -> Self {
Self {
Expand Down
21 changes: 13 additions & 8 deletions crates/uv-distribution-types/src/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,19 @@ impl Edge {
impl From<&ResolvedDist> for RequirementSource {
fn from(resolved_dist: &ResolvedDist) -> Self {
match resolved_dist {
ResolvedDist::Installable { dist, version } => match dist {
Dist::Built(BuiltDist::Registry(wheels)) => RequirementSource::Registry {
specifier: uv_pep440::VersionSpecifiers::from(
uv_pep440::VersionSpecifier::equals_version(version.clone()),
),
index: Some(wheels.best_wheel().index.url().clone()),
conflict: None,
},
ResolvedDist::Installable { dist, .. } => match dist {
Dist::Built(BuiltDist::Registry(wheels)) => {
let wheel = wheels.best_wheel();
RequirementSource::Registry {
specifier: uv_pep440::VersionSpecifiers::from(
uv_pep440::VersionSpecifier::equals_version(
wheel.filename.version.clone(),
),
),
index: Some(wheel.index.url().clone()),
conflict: None,
}
}
Dist::Built(BuiltDist::DirectUrl(wheel)) => {
let mut location = wheel.url.to_url();
location.set_fragment(None);
Expand Down
21 changes: 13 additions & 8 deletions crates/uv-distribution-types/src/resolved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ use crate::{
#[derive(Debug, Clone, Hash)]
#[allow(clippy::large_enum_variant)]
pub enum ResolvedDist {
Installed { dist: InstalledDist },
Installable { dist: Dist, version: Version },
Installed {
dist: InstalledDist,
},
Installable {
dist: Dist,
version: Option<Version>,
},
}

/// A variant of [`ResolvedDist`] with borrowed inner distributions.
Expand Down Expand Up @@ -76,11 +81,11 @@ impl ResolvedDist {
}
}

/// Returns the version of the distribution.
pub fn version(&self) -> &Version {
/// Returns the version of the distribution, if available.
pub fn version(&self) -> Option<&Version> {
match self {
Self::Installable { version, .. } => version,
Self::Installed { dist } => dist.version(),
Self::Installable { version, dist } => dist.version().or(version.as_ref()),
Self::Installed { dist } => Some(dist.version()),
}
}
}
Expand All @@ -99,7 +104,7 @@ impl ResolvedDistRef<'_> {
);
ResolvedDist::Installable {
dist: Dist::Source(SourceDist::Registry(source)),
version: sdist.version.clone(),
version: Some(sdist.version.clone()),
}
}
Self::InstallableRegistryBuiltDist {
Expand All @@ -115,7 +120,7 @@ impl ResolvedDistRef<'_> {
let built = prioritized.built_dist().expect("at least one wheel");
ResolvedDist::Installable {
dist: Dist::Built(BuiltDist::Registry(built)),
version: wheel.filename.version.clone(),
version: Some(wheel.filename.version.clone()),
}
}
Self::Installed { dist } => ResolvedDist::Installed {
Expand Down
10 changes: 8 additions & 2 deletions crates/uv-resolver/src/lock/installable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,10 @@ pub trait Installable<'lock> {
build_options,
)?;
let version = package.version().clone();
let dist = ResolvedDist::Installable { dist, version };
let dist = ResolvedDist::Installable {
dist,
version: Some(version),
};
let hashes = package.hashes();
Ok(Node::Dist {
dist,
Expand All @@ -362,7 +365,10 @@ pub trait Installable<'lock> {
&BuildOptions::default(),
)?;
let version = package.version().clone();
let dist = ResolvedDist::Installable { dist, version };
let dist = ResolvedDist::Installable {
dist,
version: Some(version),
};
let hashes = package.hashes();
Ok(Node::Dist {
dist,
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-resolver/src/resolution/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ impl ResolverOutput {
(
ResolvedDist::Installable {
dist,
version: version.clone(),
version: Some(version.clone()),
},
hashes,
Some(metadata),
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-resolver/src/resolver/derivation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl DerivationChainBuilder {
name.clone(),
p1.extra().cloned(),
p1.dev().cloned(),
version.clone(),
Some(version.clone()),
v2.clone(),
));

Expand Down
112 changes: 73 additions & 39 deletions crates/uv/src/commands/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,52 +296,86 @@ fn format_chain(name: &PackageName, version: Option<&Version>, chain: &Derivatio
range.filter(|range| *range != Ranges::empty() && *range != Ranges::full())
{
if let Some(extra) = &step.extra {
// Ex) `flask[dotenv]>=1.0.0` (v1.2.3)
format!(
"`{}{}` ({})",
format!("{}[{}]", step.name, extra).cyan(),
range.cyan(),
format!("v{}", step.version).cyan(),
)
if let Some(version) = step.version.as_ref() {
// Ex) `flask[dotenv]>=1.0.0` (v1.2.3)
format!(
"`{}{}` ({})",
format!("{}[{}]", step.name, extra).cyan(),
range.cyan(),
format!("v{version}").cyan(),
)
} else {
// Ex) `flask[dotenv]>=1.0.0`
format!(
"`{}{}`",
format!("{}[{}]", step.name, extra).cyan(),
range.cyan(),
)
}
} else if let Some(group) = &step.group {
// Ex) `flask:dev>=1.0.0` (v1.2.3)
format!(
"`{}{}` ({})",
format!("{}:{}", step.name, group).cyan(),
range.cyan(),
format!("v{}", step.version).cyan(),
)
if let Some(version) = step.version.as_ref() {
// Ex) `flask:dev>=1.0.0` (v1.2.3)
format!(
"`{}{}` ({})",
format!("{}:{}", step.name, group).cyan(),
range.cyan(),
format!("v{version}").cyan(),
)
} else {
// Ex) `flask:dev>=1.0.0`
format!(
"`{}{}`",
format!("{}:{}", step.name, group).cyan(),
range.cyan(),
)
}
} else {
// Ex) `flask>=1.0.0` (v1.2.3)
format!(
"`{}{}` ({})",
step.name.cyan(),
range.cyan(),
format!("v{}", step.version).cyan(),
)
if let Some(version) = step.version.as_ref() {
// Ex) `flask>=1.0.0` (v1.2.3)
format!(
"`{}{}` ({})",
step.name.cyan(),
range.cyan(),
format!("v{version}").cyan(),
)
} else {
// Ex) `flask>=1.0.0`
format!("`{}{}`", step.name.cyan(), range.cyan(),)
}
}
} else {
if let Some(extra) = &step.extra {
// Ex) `flask[dotenv]` (v1.2.3)
format!(
"`{}` ({})",
format!("{}[{}]", step.name, extra).cyan(),
format!("v{}", step.version).cyan(),
)
if let Some(version) = step.version.as_ref() {
// Ex) `flask[dotenv]` (v1.2.3)
format!(
"`{}` ({})",
format!("{}[{}]", step.name, extra).cyan(),
format!("v{version}").cyan(),
)
} else {
// Ex) `flask[dotenv]`
format!("`{}`", format!("{}[{}]", step.name, extra).cyan(),)
}
} else if let Some(group) = &step.group {
// Ex) `flask:dev` (v1.2.3)
format!(
"`{}` ({})",
format!("{}:{}", step.name, group).cyan(),
format!("v{}", step.version).cyan(),
)
if let Some(version) = step.version.as_ref() {
// Ex) `flask:dev` (v1.2.3)
format!(
"`{}` ({})",
format!("{}:{}", step.name, group).cyan(),
format!("v{version}").cyan(),
)
} else {
// Ex) `flask:dev`
format!("`{}`", format!("{}:{}", step.name, group).cyan(),)
}
} else {
// Ex) `flask` (v1.2.3)
format!(
"`{}` ({})",
step.name.cyan(),
format!("v{}", step.version).cyan()
)
if let Some(version) = step.version.as_ref() {
// Ex) `flask` (v1.2.3)
format!("`{}` ({})", step.name.cyan(), format!("v{version}").cyan())
} else {
// Ex) `flask`
format!("`{}`", step.name.cyan())
}
}
}
}
Expand Down

0 comments on commit bb87ef8

Please sign in to comment.