mirror of https://github.com/astral-sh/uv
Remove `Option` from preference marker (#9304)
## Summary This... _should_ be equivalent?
This commit is contained in:
parent
40844048af
commit
b9e9b60232
|
|
@ -138,23 +138,12 @@ impl CandidateSelector {
|
||||||
) -> Option<Candidate> {
|
) -> Option<Candidate> {
|
||||||
// In the branches, we "sort" the preferences by marker-matching through an iterator that
|
// In the branches, we "sort" the preferences by marker-matching through an iterator that
|
||||||
// first has the matching half and then the mismatching half.
|
// first has the matching half and then the mismatching half.
|
||||||
let preferences_match =
|
let preferences_match = preferences
|
||||||
preferences
|
.get(package_name)
|
||||||
.get(package_name)
|
.filter(|(marker, _index, _version)| env.included_by_marker(marker));
|
||||||
.filter(|(marker, _index, _version)| {
|
let preferences_mismatch = preferences
|
||||||
// `.unwrap_or(true)` because the universal marker is considered matching.
|
.get(package_name)
|
||||||
marker
|
.filter(|(marker, _index, _version)| !env.included_by_marker(marker));
|
||||||
.map(|marker| env.included_by_marker(marker))
|
|
||||||
.unwrap_or(true)
|
|
||||||
});
|
|
||||||
let preferences_mismatch =
|
|
||||||
preferences
|
|
||||||
.get(package_name)
|
|
||||||
.filter(|(marker, _index, _version)| {
|
|
||||||
marker
|
|
||||||
.map(|marker| !env.included_by_marker(marker))
|
|
||||||
.unwrap_or(false)
|
|
||||||
});
|
|
||||||
let preferences = preferences_match.chain(preferences_mismatch).filter_map(
|
let preferences = preferences_match.chain(preferences_mismatch).filter_map(
|
||||||
|(marker, source, version)| {
|
|(marker, source, version)| {
|
||||||
// If the package is mapped to an explicit index, only consider preferences that
|
// If the package is mapped to an explicit index, only consider preferences that
|
||||||
|
|
@ -178,7 +167,7 @@ impl CandidateSelector {
|
||||||
/// Return the first preference that satisfies the current range and is allowed.
|
/// Return the first preference that satisfies the current range and is allowed.
|
||||||
fn get_preferred_from_iter<'a, InstalledPackages: InstalledPackagesProvider>(
|
fn get_preferred_from_iter<'a, InstalledPackages: InstalledPackagesProvider>(
|
||||||
&'a self,
|
&'a self,
|
||||||
preferences: impl Iterator<Item = (Option<&'a MarkerTree>, &'a Version)>,
|
preferences: impl Iterator<Item = (&'a MarkerTree, &'a Version)>,
|
||||||
package_name: &'a PackageName,
|
package_name: &'a PackageName,
|
||||||
range: &Range<Version>,
|
range: &Range<Version>,
|
||||||
version_maps: &'a [VersionMap],
|
version_maps: &'a [VersionMap],
|
||||||
|
|
@ -226,7 +215,7 @@ impl CandidateSelector {
|
||||||
AllowPrerelease::No => false,
|
AllowPrerelease::No => false,
|
||||||
// If the pre-release is "global" (i.e., provided via a lockfile, rather than
|
// If the pre-release is "global" (i.e., provided via a lockfile, rather than
|
||||||
// a fork), accept it unless pre-releases are completely banned.
|
// a fork), accept it unless pre-releases are completely banned.
|
||||||
AllowPrerelease::IfNecessary => marker.is_none(),
|
AllowPrerelease::IfNecessary => marker.is_true(),
|
||||||
};
|
};
|
||||||
if !allow {
|
if !allow {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ impl Preference {
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct Entry {
|
struct Entry {
|
||||||
marker: Option<MarkerTree>,
|
marker: MarkerTree,
|
||||||
index: Option<IndexUrl>,
|
index: Option<IndexUrl>,
|
||||||
pin: Pin,
|
pin: Pin,
|
||||||
}
|
}
|
||||||
|
|
@ -169,7 +169,7 @@ impl Preferences {
|
||||||
slf.insert(
|
slf.insert(
|
||||||
preference.name,
|
preference.name,
|
||||||
preference.index,
|
preference.index,
|
||||||
None,
|
MarkerTree::TRUE,
|
||||||
Pin {
|
Pin {
|
||||||
version: preference.version,
|
version: preference.version,
|
||||||
hashes: preference.hashes,
|
hashes: preference.hashes,
|
||||||
|
|
@ -180,7 +180,7 @@ impl Preferences {
|
||||||
slf.insert(
|
slf.insert(
|
||||||
preference.name.clone(),
|
preference.name.clone(),
|
||||||
preference.index.clone(),
|
preference.index.clone(),
|
||||||
Some(fork_marker),
|
fork_marker,
|
||||||
Pin {
|
Pin {
|
||||||
version: preference.version.clone(),
|
version: preference.version.clone(),
|
||||||
hashes: preference.hashes.clone(),
|
hashes: preference.hashes.clone(),
|
||||||
|
|
@ -198,7 +198,7 @@ impl Preferences {
|
||||||
&mut self,
|
&mut self,
|
||||||
package_name: PackageName,
|
package_name: PackageName,
|
||||||
index: Option<IndexUrl>,
|
index: Option<IndexUrl>,
|
||||||
markers: Option<MarkerTree>,
|
markers: MarkerTree,
|
||||||
pin: impl Into<Pin>,
|
pin: impl Into<Pin>,
|
||||||
) {
|
) {
|
||||||
self.0.entry(package_name).or_default().push(Entry {
|
self.0.entry(package_name).or_default().push(Entry {
|
||||||
|
|
@ -214,19 +214,15 @@ impl Preferences {
|
||||||
) -> impl Iterator<
|
) -> impl Iterator<
|
||||||
Item = (
|
Item = (
|
||||||
&PackageName,
|
&PackageName,
|
||||||
impl Iterator<Item = (Option<&MarkerTree>, Option<&IndexUrl>, &Version)>,
|
impl Iterator<Item = (&MarkerTree, Option<&IndexUrl>, &Version)>,
|
||||||
),
|
),
|
||||||
> {
|
> {
|
||||||
self.0.iter().map(|(name, preferences)| {
|
self.0.iter().map(|(name, preferences)| {
|
||||||
(
|
(
|
||||||
name,
|
name,
|
||||||
preferences.iter().map(|entry| {
|
preferences
|
||||||
(
|
.iter()
|
||||||
entry.marker.as_ref(),
|
.map(|entry| (&entry.marker, entry.index.as_ref(), entry.pin.version())),
|
||||||
entry.index.as_ref(),
|
|
||||||
entry.pin.version(),
|
|
||||||
)
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -235,14 +231,12 @@ impl Preferences {
|
||||||
pub(crate) fn get(
|
pub(crate) fn get(
|
||||||
&self,
|
&self,
|
||||||
package_name: &PackageName,
|
package_name: &PackageName,
|
||||||
) -> impl Iterator<Item = (Option<&MarkerTree>, Option<&IndexUrl>, &Version)> {
|
) -> impl Iterator<Item = (&MarkerTree, Option<&IndexUrl>, &Version)> {
|
||||||
self.0.get(package_name).into_iter().flatten().map(|entry| {
|
self.0
|
||||||
(
|
.get(package_name)
|
||||||
entry.marker.as_ref(),
|
.into_iter()
|
||||||
entry.index.as_ref(),
|
.flatten()
|
||||||
entry.pin.version(),
|
.map(|entry| (&entry.marker, entry.index.as_ref(), entry.pin.version()))
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the hashes for a package, if the version matches that of the pin.
|
/// Return the hashes for a package, if the version matches that of the pin.
|
||||||
|
|
|
||||||
|
|
@ -382,7 +382,11 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
|
||||||
preferences.insert(
|
preferences.insert(
|
||||||
package.name.clone(),
|
package.name.clone(),
|
||||||
package.index.clone(),
|
package.index.clone(),
|
||||||
resolution.env.try_markers().cloned(),
|
resolution
|
||||||
|
.env
|
||||||
|
.try_markers()
|
||||||
|
.cloned()
|
||||||
|
.unwrap_or(MarkerTree::TRUE),
|
||||||
version.clone(),
|
version.clone(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue