mirror of https://github.com/astral-sh/uv
Shrink `solve()` a little by moving formatting out (#2506)
`solve()` is our main loop. Shrinking it down a little by moving formatting out makes it easier to follow.
This commit is contained in:
parent
ecc46c5412
commit
060a2fb80b
|
|
@ -1,3 +1,5 @@
|
|||
use std::fmt::{Display, Formatter};
|
||||
|
||||
use pep440_rs::VersionSpecifiers;
|
||||
use platform_tags::{IncompatibleTag, TagCompatibility, TagPriority};
|
||||
use pypi_types::{Hashes, Yanked};
|
||||
|
|
@ -44,6 +46,68 @@ pub enum IncompatibleDist {
|
|||
Unavailable,
|
||||
}
|
||||
|
||||
impl Display for IncompatibleDist {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Wheel(incompatibility) => match incompatibility {
|
||||
IncompatibleWheel::NoBinary => {
|
||||
f.write_str("no source distribution is available and using wheels is disabled")
|
||||
}
|
||||
IncompatibleWheel::Tag(tag) => match tag {
|
||||
IncompatibleTag::Invalid => {
|
||||
f.write_str("no wheels are available with valid tags")
|
||||
}
|
||||
IncompatibleTag::Python => {
|
||||
f.write_str("no wheels are available with a matching Python implementation")
|
||||
}
|
||||
IncompatibleTag::Abi => {
|
||||
f.write_str("no wheels are available with a matching Python ABI")
|
||||
}
|
||||
IncompatibleTag::Platform => {
|
||||
f.write_str("no wheels are available with a matching platform")
|
||||
}
|
||||
},
|
||||
IncompatibleWheel::Yanked(yanked) => match yanked {
|
||||
Yanked::Bool(_) => f.write_str("it was yanked"),
|
||||
Yanked::Reason(reason) => write!(
|
||||
f,
|
||||
"it was yanked (reason: {})",
|
||||
reason.trim().trim_end_matches('.')
|
||||
),
|
||||
},
|
||||
IncompatibleWheel::ExcludeNewer(ts) => match ts {
|
||||
Some(_) => f.write_str("it was published after the exclude newer time"),
|
||||
None => f.write_str("it has no publish time"),
|
||||
},
|
||||
IncompatibleWheel::RequiresPython(python) => {
|
||||
write!(f, "it requires at python {python}")
|
||||
}
|
||||
},
|
||||
Self::Source(incompatibility) => match incompatibility {
|
||||
IncompatibleSource::NoBuild => {
|
||||
f.write_str("no wheels are usable and building from source is disabled")
|
||||
}
|
||||
IncompatibleSource::Yanked(yanked) => match yanked {
|
||||
Yanked::Bool(_) => f.write_str("it was yanked"),
|
||||
Yanked::Reason(reason) => write!(
|
||||
f,
|
||||
"it was yanked (reason: {})",
|
||||
reason.trim().trim_end_matches('.')
|
||||
),
|
||||
},
|
||||
IncompatibleSource::ExcludeNewer(ts) => match ts {
|
||||
Some(_) => f.write_str("it was published after the exclude newer time"),
|
||||
None => f.write_str("it has no publish time"),
|
||||
},
|
||||
IncompatibleSource::RequiresPython(python) => {
|
||||
write!(f, "it requires python {python}")
|
||||
}
|
||||
},
|
||||
Self::Unavailable => f.write_str("no distributions are available"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum WheelCompatibility {
|
||||
Incompatible(IncompatibleWheel),
|
||||
|
|
|
|||
|
|
@ -21,10 +21,11 @@ use distribution_types::{
|
|||
BuiltDist, Dist, DistributionMetadata, IncompatibleDist, IncompatibleSource, IncompatibleWheel,
|
||||
Name, RemoteSource, SourceDist, VersionOrUrl,
|
||||
};
|
||||
pub(crate) use locals::Locals;
|
||||
use pep440_rs::{Version, MIN_VERSION};
|
||||
use pep508_rs::{MarkerEnvironment, Requirement};
|
||||
use platform_tags::{IncompatibleTag, Tags};
|
||||
use pypi_types::{Metadata23, Yanked};
|
||||
use platform_tags::Tags;
|
||||
use pypi_types::Metadata23;
|
||||
pub(crate) use urls::Urls;
|
||||
use uv_client::{FlatIndex, RegistryClient};
|
||||
use uv_distribution::DistributionDatabase;
|
||||
|
|
@ -52,10 +53,8 @@ pub use crate::resolver::provider::{
|
|||
};
|
||||
use crate::resolver::reporter::Facade;
|
||||
pub use crate::resolver::reporter::{BuildId, Reporter};
|
||||
|
||||
use crate::yanks::AllowedYanks;
|
||||
use crate::{DependencyMode, Options};
|
||||
pub(crate) use locals::Locals;
|
||||
|
||||
mod index;
|
||||
mod locals;
|
||||
|
|
@ -347,8 +346,12 @@ impl<'a, Provider: ResolverProvider> Resolver<'a, Provider> {
|
|||
// them as incompatible dependencies instead of marking the package version
|
||||
// as unavailable directly
|
||||
UnavailableVersion::IncompatibleDist(
|
||||
IncompatibleDist::Source(IncompatibleSource::RequiresPython(requires_python))
|
||||
| IncompatibleDist::Wheel(IncompatibleWheel::RequiresPython(requires_python))
|
||||
IncompatibleDist::Source(IncompatibleSource::RequiresPython(
|
||||
requires_python,
|
||||
))
|
||||
| IncompatibleDist::Wheel(IncompatibleWheel::RequiresPython(
|
||||
requires_python,
|
||||
)),
|
||||
) => {
|
||||
let python_version = requires_python
|
||||
.iter()
|
||||
|
|
@ -369,51 +372,7 @@ impl<'a, Provider: ResolverProvider> Resolver<'a, Provider> {
|
|||
continue;
|
||||
}
|
||||
UnavailableVersion::IncompatibleDist(incompatibility) => {
|
||||
match incompatibility {
|
||||
IncompatibleDist::Wheel(incompatibility) => {
|
||||
match incompatibility {
|
||||
IncompatibleWheel::NoBinary => "no source distribution is available and using wheels is disabled".to_string(),
|
||||
IncompatibleWheel::Tag(tag) => {
|
||||
match tag {
|
||||
IncompatibleTag::Invalid => "no wheels are available with valid tags".to_string(),
|
||||
IncompatibleTag::Python => "no wheels are available with a matching Python implementation".to_string(),
|
||||
IncompatibleTag::Abi => "no wheels are available with a matching Python ABI".to_string(),
|
||||
IncompatibleTag::Platform => "no wheels are available with a matching platform".to_string(),
|
||||
}
|
||||
}
|
||||
IncompatibleWheel::Yanked(yanked) => match yanked {
|
||||
Yanked::Bool(_) => "it was yanked".to_string(),
|
||||
Yanked::Reason(reason) => format!(
|
||||
"it was yanked (reason: {})",
|
||||
reason.trim().trim_end_matches('.')
|
||||
),
|
||||
},
|
||||
IncompatibleWheel::ExcludeNewer(ts) => match ts {
|
||||
Some(_) => "it was published after the exclude newer time".to_string(),
|
||||
None => "it has no publish time".to_string()
|
||||
}
|
||||
IncompatibleWheel::RequiresPython(_) => unreachable!(),
|
||||
}
|
||||
}
|
||||
IncompatibleDist::Source(incompatibility) => {
|
||||
match incompatibility {
|
||||
IncompatibleSource::NoBuild => "no wheels are usable and building from source is disabled".to_string(),
|
||||
IncompatibleSource::Yanked(yanked) => match yanked {
|
||||
Yanked::Bool(_) => "it was yanked".to_string(),
|
||||
Yanked::Reason(reason) => format!(
|
||||
"it was yanked (reason: {})",
|
||||
reason.trim().trim_end_matches('.')
|
||||
),
|
||||
},
|
||||
IncompatibleSource::ExcludeNewer(ts) => match ts {
|
||||
Some(_) => "it was published after the exclude newer time".to_string(),
|
||||
None => "it has no publish time".to_string()
|
||||
}
|
||||
IncompatibleSource::RequiresPython(_) => unreachable!(),
|
||||
}
|
||||
}
|
||||
IncompatibleDist::Unavailable => "no distributions are available".to_string()
|
||||
}
|
||||
incompatibility.to_string()
|
||||
}
|
||||
};
|
||||
state.add_incompatibility(Incompatibility::unavailable(
|
||||
|
|
|
|||
Loading…
Reference in New Issue