mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-01 06:21:13 +00:00
Log origin of version selection (#5186)
Log whether a version was picked because it was the next version or because it was a preference (installed, lockfile or sibling fork)
This commit is contained in:
parent
d54ae4e381
commit
93ba676f2e
2 changed files with 60 additions and 8 deletions
|
@ -1,5 +1,6 @@
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use pubgrub::range::Range;
|
use pubgrub::range::Range;
|
||||||
|
use std::fmt::{Display, Formatter};
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
use distribution_types::{CompatibleDist, IncompatibleDist, IncompatibleSource};
|
use distribution_types::{CompatibleDist, IncompatibleDist, IncompatibleSource};
|
||||||
|
@ -132,6 +133,7 @@ impl CandidateSelector {
|
||||||
dist: CandidateDist::Compatible(CompatibleDist::InstalledDist(
|
dist: CandidateDist::Compatible(CompatibleDist::InstalledDist(
|
||||||
dist,
|
dist,
|
||||||
)),
|
)),
|
||||||
|
choice_kind: VersionChoiceKind::Preference,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,7 +150,12 @@ impl CandidateSelector {
|
||||||
.iter()
|
.iter()
|
||||||
.find_map(|version_map| version_map.get(version))
|
.find_map(|version_map| version_map.get(version))
|
||||||
{
|
{
|
||||||
return Some(Candidate::new(package_name, version, file));
|
return Some(Candidate::new(
|
||||||
|
package_name,
|
||||||
|
version,
|
||||||
|
file,
|
||||||
|
VersionChoiceKind::Preference,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,6 +174,7 @@ impl CandidateSelector {
|
||||||
name: package_name,
|
name: package_name,
|
||||||
version,
|
version,
|
||||||
dist: CandidateDist::Compatible(CompatibleDist::InstalledDist(dist)),
|
dist: CandidateDist::Compatible(CompatibleDist::InstalledDist(dist)),
|
||||||
|
choice_kind: VersionChoiceKind::Installed,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -311,7 +319,12 @@ impl CandidateSelector {
|
||||||
);
|
);
|
||||||
// If pre-releases are allowed, treat them equivalently
|
// If pre-releases are allowed, treat them equivalently
|
||||||
// to stable distributions.
|
// to stable distributions.
|
||||||
Candidate::new(package_name, version, dist)
|
Candidate::new(
|
||||||
|
package_name,
|
||||||
|
version,
|
||||||
|
dist,
|
||||||
|
VersionChoiceKind::Compatible,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
AllowPreRelease::IfNecessary => {
|
AllowPreRelease::IfNecessary => {
|
||||||
let Some(dist) = maybe_dist.prioritized_dist() else {
|
let Some(dist) = maybe_dist.prioritized_dist() else {
|
||||||
|
@ -350,7 +363,7 @@ impl CandidateSelector {
|
||||||
steps,
|
steps,
|
||||||
version,
|
version,
|
||||||
);
|
);
|
||||||
Candidate::new(package_name, version, dist)
|
Candidate::new(package_name, version, dist, VersionChoiceKind::Compatible)
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -384,9 +397,12 @@ impl CandidateSelector {
|
||||||
match prerelease {
|
match prerelease {
|
||||||
None => None,
|
None => None,
|
||||||
Some(PreReleaseCandidate::NotNecessary) => None,
|
Some(PreReleaseCandidate::NotNecessary) => None,
|
||||||
Some(PreReleaseCandidate::IfNecessary(version, dist)) => {
|
Some(PreReleaseCandidate::IfNecessary(version, dist)) => Some(Candidate::new(
|
||||||
Some(Candidate::new(package_name, version, dist))
|
package_name,
|
||||||
}
|
version,
|
||||||
|
dist,
|
||||||
|
VersionChoiceKind::Compatible,
|
||||||
|
)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -418,6 +434,28 @@ impl<'a> From<&'a PrioritizedDist> for CandidateDist<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The reason why we selected the version of the candidate version, either a preference or being
|
||||||
|
/// compatible.
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub(crate) enum VersionChoiceKind {
|
||||||
|
/// A preference from an output file such as `-o requirements.txt` or `uv.lock`.
|
||||||
|
Preference,
|
||||||
|
/// A preference from an installed version.
|
||||||
|
Installed,
|
||||||
|
/// The next compatible version in a version map
|
||||||
|
Compatible,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for VersionChoiceKind {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
VersionChoiceKind::Preference => f.write_str("preference"),
|
||||||
|
VersionChoiceKind::Installed => f.write_str("installed"),
|
||||||
|
VersionChoiceKind::Compatible => f.write_str("compatible"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub(crate) struct Candidate<'a> {
|
pub(crate) struct Candidate<'a> {
|
||||||
/// The name of the package.
|
/// The name of the package.
|
||||||
|
@ -426,14 +464,22 @@ pub(crate) struct Candidate<'a> {
|
||||||
version: &'a Version,
|
version: &'a Version,
|
||||||
/// The distributions to use for resolving and installing the package.
|
/// The distributions to use for resolving and installing the package.
|
||||||
dist: CandidateDist<'a>,
|
dist: CandidateDist<'a>,
|
||||||
|
/// Whether this candidate was selected from a preference.
|
||||||
|
choice_kind: VersionChoiceKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Candidate<'a> {
|
impl<'a> Candidate<'a> {
|
||||||
fn new(name: &'a PackageName, version: &'a Version, dist: &'a PrioritizedDist) -> Self {
|
fn new(
|
||||||
|
name: &'a PackageName,
|
||||||
|
version: &'a Version,
|
||||||
|
dist: &'a PrioritizedDist,
|
||||||
|
choice_kind: VersionChoiceKind,
|
||||||
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
name,
|
name,
|
||||||
version,
|
version,
|
||||||
dist: CandidateDist::from(dist),
|
dist: CandidateDist::from(dist),
|
||||||
|
choice_kind,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,6 +502,11 @@ impl<'a> Candidate<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return this candidate was selected from a preference.
|
||||||
|
pub(crate) fn choice_kind(&self) -> VersionChoiceKind {
|
||||||
|
self.choice_kind
|
||||||
|
}
|
||||||
|
|
||||||
/// Return the distribution for the candidate.
|
/// Return the distribution for the candidate.
|
||||||
pub(crate) fn dist(&self) -> &CandidateDist<'a> {
|
pub(crate) fn dist(&self) -> &CandidateDist<'a> {
|
||||||
&self.dist
|
&self.dist
|
||||||
|
|
|
@ -1061,9 +1061,10 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
|
||||||
};
|
};
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"Selecting: {}=={} ({})",
|
"Selecting: {}=={} [{}] ({})",
|
||||||
name,
|
name,
|
||||||
candidate.version(),
|
candidate.version(),
|
||||||
|
candidate.choice_kind(),
|
||||||
filename,
|
filename,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue