1use std::collections::BTreeMap;
2use std::collections::Bound;
3use std::ops::RangeBounds;
4use std::sync::OnceLock;
5
6use jiff::Timestamp;
7use pubgrub::Ranges;
8use tracing::{instrument, trace};
9
10use uv_client::{FlatIndexEntry, OwnedArchive, SimpleDetailMetadata, VersionFiles};
11use uv_configuration::BuildOptions;
12use uv_distribution_filename::{DistFilename, SourceDistFilename, WheelFilename};
13use uv_distribution_types::{
14 IndexEntryFilename, IndexUrl, MinimumLibcVersion, RegistryBuiltWheel, RegistrySourceDist,
15 RequiresPython,
16};
17use uv_normalize::PackageName;
18use uv_pep440::Version;
19use uv_platform_tags::{IncompatibleTag, TagCompatibility, Tags};
20use uv_preview::PreviewFeature;
21use uv_pypi_types::{HashDigest, ResolutionMetadata, Yanked};
22use uv_types::HashStrategy;
23use uv_warnings::warn_user_once;
24
25use crate::flat_index::FlatDistributions;
26use crate::prioritized_distribution::{
27 HashComparison, IncompatibleSource, IncompatibleWheel, PrioritizedDist, RegistryVariantsJson,
28 SourceDistCompatibility, WheelCompatibility,
29};
30use crate::yanks::AllowedYanks;
31
32#[derive(Debug)]
34pub struct VersionMap {
35 inner: VersionMapInner,
37}
38
39impl VersionMap {
40 #[instrument(skip_all, fields(package_name))]
50 pub(crate) fn from_simple_metadata(
51 simple_metadata: OwnedArchive<SimpleDetailMetadata>,
52 package_name: &PackageName,
53 index: IndexUrl,
54 tags: Option<Tags>,
55 requires_python: RequiresPython,
56 allowed_yanks: AllowedYanks,
57 hasher: HashStrategy,
58 included_version_cutoff: Option<Timestamp>,
59 available_version_cutoff: Option<Timestamp>,
60 flat_index: Option<FlatDistributions>,
61 build_options: &BuildOptions,
62 minimum_libc_version: Option<MinimumLibcVersion>,
63 ) -> Self {
64 let mut local = false;
65 let mut entries = Vec::with_capacity(simple_metadata.iter().size_hint().0);
66 for (datum_index, datum) in simple_metadata.iter().enumerate() {
70 if datum.files.wheels.is_empty() && datum.files.source_dists.is_empty() {
72 continue;
73 }
74 let version = rkyv::deserialize::<Version, rkyv::rancor::Error>(&datum.version)
75 .expect("archived version always deserializes");
76
77 local |= version.is_local();
78 debug_assert!(
79 entries
80 .last()
81 .is_none_or(|entry: &VersionMapLazyEntry| entry.version < version),
82 "simple metadata versions must be sorted and unique"
83 );
84 entries.push(VersionMapLazyEntry {
85 version,
86 dist: LazyPrioritizedDist {
87 flat: None,
88 simple: Some(SimplePrioritizedDist {
89 datum_index,
90 dist: OnceLock::new(),
91 }),
92 },
93 });
94 }
95 let mut map = VersionMapLazyIndex { entries };
96 if let Some(flat_index) = flat_index {
99 map = map.merge_flat(flat_index);
100 }
101 Self {
102 inner: VersionMapInner::Lazy(VersionMapLazy {
103 package_name: package_name.clone(),
104 map,
105 local,
106 simple_metadata,
107 no_binary: build_options.no_binary_package(package_name),
108 no_build: build_options.no_build_package(package_name),
109 index,
110 tags,
111 allowed_yanks,
112 hasher,
113 requires_python,
114 included_version_cutoff,
115 available_version_cutoff,
116 minimum_libc_version,
117 }),
118 }
119 }
120
121 #[instrument(skip_all, fields(package_name))]
122 pub(crate) fn from_flat_metadata(
123 flat_metadata: Vec<FlatIndexEntry>,
124 tags: Option<&Tags>,
125 hasher: &HashStrategy,
126 build_options: &BuildOptions,
127 minimum_libc_version: Option<MinimumLibcVersion>,
128 ) -> Self {
129 FlatDistributions::from_entries(
130 flat_metadata,
131 tags,
132 hasher,
133 build_options,
134 minimum_libc_version,
135 )
136 .into()
137 }
138
139 pub(crate) fn get_metadata(&self, version: &Version) -> Option<ResolutionMetadata> {
141 match self.inner {
142 VersionMapInner::Eager(_) => None,
143 VersionMapInner::Lazy(ref lazy) => lazy.get_metadata(version),
144 }
145 }
146
147 pub(crate) fn get(&self, version: &Version) -> Option<&PrioritizedDist> {
149 match self.inner {
150 VersionMapInner::Eager(ref eager) => eager.map.get(version),
151 VersionMapInner::Lazy(ref lazy) => lazy.get(version),
152 }
153 }
154
155 pub(crate) fn versions(&self) -> impl DoubleEndedIterator<Item = &Version> {
157 match &self.inner {
158 VersionMapInner::Eager(eager) => either::Either::Left(eager.map.keys()),
159 VersionMapInner::Lazy(lazy) => either::Either::Right(lazy.map.keys()),
160 }
161 }
162
163 pub(crate) fn included_versions(&self) -> impl DoubleEndedIterator<Item = &Version> {
171 match &self.inner {
172 VersionMapInner::Eager(eager) => either::Either::Left(eager.map.keys()),
173 VersionMapInner::Lazy(lazy) => either::Either::Right(lazy.included_versions()),
174 }
175 }
176
177 pub(crate) fn index(&self) -> Option<&IndexUrl> {
179 match &self.inner {
180 VersionMapInner::Eager(_) => None,
181 VersionMapInner::Lazy(lazy) => Some(&lazy.index),
182 }
183 }
184
185 pub(crate) fn mismatched_wheel_name(&self) -> Option<PackageName> {
187 match &self.inner {
188 VersionMapInner::Eager(_) => None,
189 VersionMapInner::Lazy(lazy) => lazy.simple_metadata.mismatched_wheel_name(),
190 }
191 }
192
193 pub(crate) fn included_version_cutoff(&self) -> Option<&Timestamp> {
195 match &self.inner {
196 VersionMapInner::Eager(_) => None,
197 VersionMapInner::Lazy(lazy) => lazy.included_version_cutoff.as_ref(),
198 }
199 }
200
201 pub(crate) fn iter(
208 &self,
209 range: &Ranges<Version>,
210 ) -> impl DoubleEndedIterator<Item = (&Version, VersionMapDistHandle<'_>)> {
211 if let Some(version) = range.as_singleton() {
213 either::Either::Left(match self.inner {
214 VersionMapInner::Eager(ref eager) => {
215 either::Either::Left(eager.map.get_key_value(version).into_iter().map(
216 move |(version, dist)| {
217 let version_map_dist = VersionMapDistHandle {
218 inner: VersionMapDistHandleInner::Eager(dist),
219 };
220 (version, version_map_dist)
221 },
222 ))
223 }
224 VersionMapInner::Lazy(ref lazy) => {
225 either::Either::Right(lazy.map.get(version).into_iter().map(move |entry| {
226 let version_map_dist = VersionMapDistHandle {
227 inner: VersionMapDistHandleInner::Lazy {
228 lazy,
229 dist: &entry.dist,
230 },
231 };
232 (&entry.version, version_map_dist)
233 }))
234 }
235 })
236 } else {
237 either::Either::Right(match self.inner {
238 VersionMapInner::Eager(ref eager) => {
239 either::Either::Left(eager.map.range(BoundingRange::from(range)).map(
240 |(version, dist)| {
241 let version_map_dist = VersionMapDistHandle {
242 inner: VersionMapDistHandleInner::Eager(dist),
243 };
244 (version, version_map_dist)
245 },
246 ))
247 }
248 VersionMapInner::Lazy(ref lazy) => {
249 either::Either::Right(lazy.map.range(BoundingRange::from(range)).iter().map(
250 |entry| {
251 let version_map_dist = VersionMapDistHandle {
252 inner: VersionMapDistHandleInner::Lazy {
253 lazy,
254 dist: &entry.dist,
255 },
256 };
257 (&entry.version, version_map_dist)
258 },
259 ))
260 }
261 })
262 }
263 }
264
265 pub(crate) fn iter_included(
271 &self,
272 range: &Ranges<Version>,
273 ) -> impl DoubleEndedIterator<Item = (&Version, VersionMapDistHandle<'_>)> {
274 self.iter(range).filter(|(_, dist)| dist.is_included())
275 }
276
277 pub(crate) fn hashes(&self, version: &Version) -> Option<&[HashDigest]> {
279 match self.inner {
280 VersionMapInner::Eager(ref eager) => {
281 eager.map.get(version).map(PrioritizedDist::hashes)
282 }
283 VersionMapInner::Lazy(ref lazy) => lazy.get(version).map(PrioritizedDist::hashes),
284 }
285 }
286
287 pub(crate) fn len(&self) -> usize {
292 match self.inner {
293 VersionMapInner::Eager(VersionMapEager { ref map, .. }) => map.len(),
294 VersionMapInner::Lazy(VersionMapLazy { ref map, .. }) => map.len(),
295 }
296 }
297
298 pub(crate) fn local(&self) -> bool {
300 match self.inner {
301 VersionMapInner::Eager(ref map) => map.local,
302 VersionMapInner::Lazy(ref map) => map.local,
303 }
304 }
305}
306
307impl From<FlatDistributions> for VersionMap {
308 fn from(flat_index: FlatDistributions) -> Self {
309 let local = flat_index.iter().any(|(version, _)| version.is_local());
310 let map = flat_index.into();
311 Self {
312 inner: VersionMapInner::Eager(VersionMapEager { map, local }),
313 }
314 }
315}
316
317pub(crate) struct VersionMapDistHandle<'a> {
330 inner: VersionMapDistHandleInner<'a>,
331}
332
333enum VersionMapDistHandleInner<'a> {
334 Eager(&'a PrioritizedDist),
335 Lazy {
336 lazy: &'a VersionMapLazy,
337 dist: &'a LazyPrioritizedDist,
338 },
339}
340
341impl<'a> VersionMapDistHandle<'a> {
342 fn is_included(&self) -> bool {
344 match self.inner {
345 VersionMapDistHandleInner::Eager(_) => true,
346 VersionMapDistHandleInner::Lazy { lazy, dist } => match (&dist.flat, &dist.simple) {
347 (Some(_), _) => true,
348 (None, Some(simple)) => lazy.any_file_materializable(simple),
349 (None, None) => false,
350 },
351 }
352 }
353
354 pub(crate) fn prioritized_dist(&self) -> Option<&'a PrioritizedDist> {
356 match self.inner {
357 VersionMapDistHandleInner::Eager(dist) => Some(dist),
358 VersionMapDistHandleInner::Lazy { lazy, dist } => Some(lazy.get_lazy(dist)?),
359 }
360 }
361}
362
363#[derive(Debug)]
365#[expect(clippy::large_enum_variant)]
366enum VersionMapInner {
367 Eager(VersionMapEager),
372 Lazy(VersionMapLazy),
378}
379
380#[derive(Debug)]
382struct VersionMapEager {
383 map: BTreeMap<Version, PrioritizedDist>,
385 local: bool,
387}
388
389#[derive(Debug)]
391struct VersionMapLazyEntry {
392 version: Version,
393 dist: LazyPrioritizedDist,
394}
395
396#[derive(Debug)]
398struct VersionMapLazyIndex {
399 entries: Vec<VersionMapLazyEntry>,
400}
401
402impl VersionMapLazyIndex {
403 fn merge_flat(self, flat_index: FlatDistributions) -> Self {
405 let flat_count = flat_index.iter().size_hint().0;
406 let mut merged = Vec::with_capacity(self.entries.len() + flat_count);
407 let mut simple = self.entries.into_iter().peekable();
408 let mut flat = flat_index.into_iter().peekable();
409 let flat_entry = |(version, dist)| VersionMapLazyEntry {
410 version,
411 dist: LazyPrioritizedDist {
412 flat: Some(dist),
413 simple: None,
414 },
415 };
416 while let (Some(simple_entry), Some((flat_version, _))) = (simple.peek(), flat.peek()) {
417 match simple_entry.version.cmp(flat_version) {
418 std::cmp::Ordering::Less => {
419 if let Some(entry) = simple.next() {
420 merged.push(entry);
421 }
422 }
423 std::cmp::Ordering::Greater => {
424 if let Some(entry) = flat.next() {
425 merged.push(flat_entry(entry));
426 }
427 }
428 std::cmp::Ordering::Equal => {
429 if let (Some(mut entry), Some((_, dist))) = (simple.next(), flat.next()) {
430 entry.dist.flat = Some(dist);
431 merged.push(entry);
432 }
433 }
434 }
435 }
436 merged.extend(simple);
437 merged.extend(flat.map(flat_entry));
438
439 Self { entries: merged }
440 }
441
442 fn get(&self, version: &Version) -> Option<&VersionMapLazyEntry> {
443 let index = self
444 .entries
445 .binary_search_by(|entry| entry.version.cmp(version))
446 .ok()?;
447 self.entries.get(index)
448 }
449
450 fn keys(&self) -> impl DoubleEndedIterator<Item = &Version> {
451 self.entries.iter().map(|entry| &entry.version)
452 }
453
454 fn range(&self, range: BoundingRange<'_>) -> &[VersionMapLazyEntry] {
455 let start = match range.min {
456 Bound::Included(version) => self
457 .entries
458 .partition_point(|entry| entry.version < *version),
459 Bound::Excluded(version) => self
460 .entries
461 .partition_point(|entry| entry.version <= *version),
462 Bound::Unbounded => 0,
463 };
464 let end = match range.max {
465 Bound::Included(version) => self
466 .entries
467 .partition_point(|entry| entry.version <= *version),
468 Bound::Excluded(version) => self
469 .entries
470 .partition_point(|entry| entry.version < *version),
471 Bound::Unbounded => self.entries.len(),
472 };
473 self.entries.get(start..end).unwrap_or_default()
474 }
475
476 fn len(&self) -> usize {
477 self.entries.len()
478 }
479}
480
481#[derive(Debug)]
490struct VersionMapLazy {
491 package_name: PackageName,
493 map: VersionMapLazyIndex,
495 local: bool,
497 simple_metadata: OwnedArchive<SimpleDetailMetadata>,
500 no_binary: bool,
502 no_build: bool,
504 index: IndexUrl,
506 tags: Option<Tags>,
509 included_version_cutoff: Option<Timestamp>,
512 available_version_cutoff: Option<Timestamp>,
514 allowed_yanks: AllowedYanks,
516 hasher: HashStrategy,
518 requires_python: RequiresPython,
520 minimum_libc_version: Option<MinimumLibcVersion>,
522}
523
524impl VersionMapLazy {
525 fn get_metadata(&self, version: &Version) -> Option<ResolutionMetadata> {
527 let archived = self
528 .map
529 .get(version)
530 .and_then(|entry| entry.dist.simple.as_ref())
531 .and_then(|simple| self.simple_metadata.datum(simple.datum_index))
532 .and_then(|datum| datum.metadata.as_deref())?;
533 Some(
534 rkyv::deserialize::<ResolutionMetadata, rkyv::rancor::Error>(archived)
535 .expect("archived metadata always deserializes"),
536 )
537 }
538
539 fn get(&self, version: &Version) -> Option<&PrioritizedDist> {
541 self.get_lazy(&self.map.get(version)?.dist)
542 }
543
544 fn included_versions(&self) -> impl DoubleEndedIterator<Item = &Version> {
547 self.map.entries.iter().filter_map(move |entry| {
548 let included = match (&entry.dist.flat, &entry.dist.simple) {
549 (Some(_), _) => true,
551 (None, Some(simple)) => self.any_file_included(simple),
552 (None, None) => false,
553 };
554 included.then_some(&entry.version)
555 })
556 }
557
558 fn any_file_included(&self, simple: &SimplePrioritizedDist) -> bool {
563 if self.included_version_cutoff.is_none() && self.available_version_cutoff.is_none() {
564 return true;
565 }
566 let Some(datum) = self.simple_metadata.datum(simple.datum_index) else {
567 return false;
568 };
569 let files = &datum.files;
570 files
571 .wheels
572 .iter()
573 .chain(files.source_dists.iter())
574 .any(|file| {
575 let upload_time = file.upload_time_utc_ms();
576 let excluded = if let Some(cutoff) = &self.included_version_cutoff {
577 upload_time.is_none_or(|t| t >= cutoff.as_millisecond())
578 } else if let Some(cutoff) = &self.available_version_cutoff {
579 upload_time.is_some_and(|t| t >= cutoff.as_millisecond())
580 } else {
581 false
582 };
583 !excluded
584 })
585 }
586
587 fn any_file_materializable(&self, simple: &SimplePrioritizedDist) -> bool {
592 let Some(cutoff) = self
593 .included_version_cutoff
594 .as_ref()
595 .or(self.available_version_cutoff.as_ref())
596 else {
597 return true;
598 };
599 let Some(datum) = self.simple_metadata.datum(simple.datum_index) else {
600 return false;
601 };
602 datum
603 .files
604 .wheels
605 .iter()
606 .chain(datum.files.source_dists.iter())
607 .any(|file| {
608 file.upload_time_utc_ms()
609 .is_none_or(|upload_time| upload_time < cutoff.as_millisecond())
610 })
611 }
612
613 fn get_lazy<'p>(&'p self, lazy_dist: &'p LazyPrioritizedDist) -> Option<&'p PrioritizedDist> {
619 match (&lazy_dist.flat, &lazy_dist.simple) {
620 (Some(flat), Some(simple)) => self.get_simple(Some(flat), simple),
621 (Some(flat), None) => Some(flat),
622 (None, Some(simple)) => self.get_simple(None, simple),
623 (None, None) => None,
624 }
625 }
626
627 fn get_simple<'p>(
632 &'p self,
633 init: Option<&'p PrioritizedDist>,
634 simple: &'p SimplePrioritizedDist,
635 ) -> Option<&'p PrioritizedDist> {
636 let get_or_init = || {
637 let files = rkyv::deserialize::<VersionFiles, rkyv::rancor::Error>(
638 &self
639 .simple_metadata
640 .datum(simple.datum_index)
641 .expect("index to lazy dist is correct")
642 .files,
643 )
644 .expect("archived version files always deserializes");
645 let mut priority_dist = init.cloned().unwrap_or_default();
646 for (filename, file) in files.all_entries(&self.package_name) {
647 let filename = match filename {
648 IndexEntryFilename::DistFilename(filename) => filename,
649 IndexEntryFilename::VariantJson(filename) => {
650 if !priority_dist
651 .variants_json()
652 .iter()
653 .any(|variants_json| variants_json.index == self.index)
654 {
655 priority_dist.insert_variants_json(RegistryVariantsJson {
656 filename,
657 file,
658 index: self.index.clone(),
659 });
660 }
661 continue;
662 }
663 };
664 let (excluded, upload_time) = if let Some(included_version_cutoff) =
667 &self.included_version_cutoff
668 {
669 match file.upload_time_utc_ms.as_ref() {
670 Some(&upload_time)
671 if upload_time >= included_version_cutoff.as_millisecond() =>
672 {
673 trace!(
674 "Excluding `{}` (uploaded {upload_time}) due to exclude-newer ({included_version_cutoff})",
675 file.filename
676 );
677 (true, Some(upload_time))
678 }
679 None => {
680 warn_user_once!(
681 "`{}` is missing an upload date, but user provided: {included_version_cutoff}",
682 file.filename,
683 );
684 (true, None)
685 }
686 _ => (false, None),
687 }
688 } else if let Some(available_version_cutoff) = &self.available_version_cutoff {
689 match file.upload_time_utc_ms.as_ref() {
690 Some(&upload_time)
691 if upload_time >= available_version_cutoff.as_millisecond() =>
692 {
693 trace!(
694 "Excluding `{}` (uploaded {upload_time}) due to available version cutoff ({available_version_cutoff})",
695 file.filename
696 );
697 (true, Some(upload_time))
698 }
699 _ => (false, None),
700 }
701 } else {
702 (false, None)
703 };
704
705 let file = file.assume_canonical();
706
707 let yanked = file.yanked.as_deref();
709 let hashes = file.hashes.clone();
710 match filename {
711 DistFilename::WheelFilename(filename) => {
712 let compatibility = self.wheel_compatibility(
713 &filename,
714 &filename.name,
715 &filename.version,
716 hashes.as_slice(),
717 yanked,
718 excluded,
719 upload_time,
720 );
721 let dist = RegistryBuiltWheel {
722 filename,
723 file: Box::new(file),
724 index: self.index.clone(),
725 size_is_authoritative: false,
726 };
727 priority_dist.insert_built(
728 dist,
729 hashes,
730 compatibility,
731 self.minimum_libc_version,
732 );
733 }
734 DistFilename::SourceDistFilename(filename) => {
735 let compatibility = self.source_dist_compatibility(
736 &filename,
737 hashes.as_slice(),
738 yanked,
739 excluded,
740 upload_time,
741 );
742 let dist = RegistrySourceDist {
743 name: filename.name.clone(),
744 version: filename.version.clone(),
745 ext: filename.extension,
746 file: Box::new(file),
747 index: self.index.clone(),
748 wheels: vec![],
749 size_is_authoritative: false,
750 };
751 priority_dist.insert_source(dist, hashes, compatibility);
752 }
753 }
754 }
755 if priority_dist.is_empty() {
756 None
757 } else {
758 Some(priority_dist)
759 }
760 };
761 simple.dist.get_or_init(get_or_init).as_ref()
762 }
763
764 fn source_dist_compatibility(
765 &self,
766 filename: &SourceDistFilename,
767 hashes: &[HashDigest],
768 yanked: Option<&Yanked>,
769 excluded: bool,
770 upload_time: Option<i64>,
771 ) -> SourceDistCompatibility {
772 if excluded {
774 return SourceDistCompatibility::Incompatible(IncompatibleSource::ExcludeNewer(
775 upload_time,
776 ));
777 }
778
779 if self.no_build {
781 return SourceDistCompatibility::Incompatible(IncompatibleSource::NoBuild);
782 }
783
784 if let Some(yanked) = yanked {
786 if yanked.is_yanked()
787 && !self
788 .allowed_yanks
789 .contains(&filename.name, &filename.version)
790 {
791 return SourceDistCompatibility::Incompatible(IncompatibleSource::Yanked(
792 yanked.clone(),
793 ));
794 }
795 }
796
797 if !filename.extension.is_pep625_compliant() {
802 return SourceDistCompatibility::Incompatible(IncompatibleSource::NotPep625Filename);
803 }
804
805 let hash_policy = self
807 .hasher
808 .archive_policy_for_package(&filename.name, &filename.version);
809 let required_hashes = hash_policy.digests();
810 let hash = if required_hashes.is_empty() {
811 HashComparison::Matched
812 } else {
813 if hashes.is_empty() {
814 HashComparison::Missing
815 } else if hash_policy.matches(hashes) {
816 HashComparison::Matched
817 } else {
818 HashComparison::Mismatched
819 }
820 };
821
822 SourceDistCompatibility::Compatible(hash)
823 }
824
825 fn wheel_compatibility(
826 &self,
827 filename: &WheelFilename,
828 name: &PackageName,
829 version: &Version,
830 hashes: &[HashDigest],
831 yanked: Option<&Yanked>,
832 excluded: bool,
833 upload_time: Option<i64>,
834 ) -> WheelCompatibility {
835 if excluded {
837 return WheelCompatibility::Incompatible(IncompatibleWheel::ExcludeNewer(upload_time));
838 }
839
840 if self.no_binary {
842 return WheelCompatibility::Incompatible(IncompatibleWheel::NoBinary);
843 }
844
845 if let Some(yanked) = yanked {
847 if yanked.is_yanked() && !self.allowed_yanks.contains(name, version) {
848 return WheelCompatibility::Incompatible(IncompatibleWheel::Yanked(yanked.clone()));
849 }
850 }
851
852 if filename.variant().is_some() && !uv_preview::is_enabled(PreviewFeature::WheelVariants) {
853 return WheelCompatibility::Incompatible(IncompatibleWheel::Tag(
854 IncompatibleTag::Variant,
855 ));
856 }
857
858 let priority = if let Some(tags) = &self.tags {
860 match filename.tag_compatibility(tags) {
861 TagCompatibility::Incompatible(tag) => {
862 return WheelCompatibility::Incompatible(IncompatibleWheel::Tag(tag));
863 }
864 TagCompatibility::Compatible(priority) => Some(priority),
865 }
866 } else {
867 if !self.requires_python.matches_wheel_tag(filename) {
870 return WheelCompatibility::Incompatible(IncompatibleWheel::Tag(
871 IncompatibleTag::AbiPythonVersion,
872 ));
873 }
874 None
875 };
876
877 let hash_policy = self.hasher.archive_policy_for_package(name, version);
879 let required_hashes = hash_policy.digests();
880 let hash = if required_hashes.is_empty() {
881 HashComparison::Matched
882 } else {
883 if hashes.is_empty() {
884 HashComparison::Missing
885 } else if hash_policy.matches(hashes) {
886 HashComparison::Matched
887 } else {
888 HashComparison::Mismatched
889 }
890 };
891
892 WheelCompatibility::from_tag_priority(filename, hash, priority)
893 }
894}
895
896#[derive(Debug)]
898struct LazyPrioritizedDist {
899 flat: Option<PrioritizedDist>,
901 simple: Option<SimplePrioritizedDist>,
903}
904
905#[derive(Debug)]
907struct SimplePrioritizedDist {
908 datum_index: usize,
912 dist: OnceLock<Option<PrioritizedDist>>,
920}
921
922#[derive(Debug)]
924struct BoundingRange<'a> {
925 min: Bound<&'a Version>,
926 max: Bound<&'a Version>,
927}
928
929impl<'a> From<&'a Ranges<Version>> for BoundingRange<'a> {
930 fn from(value: &'a Ranges<Version>) -> Self {
931 let (min, max) = value
932 .bounding_range()
933 .unwrap_or((Bound::Unbounded, Bound::Unbounded));
934 Self { min, max }
935 }
936}
937
938impl<'a> RangeBounds<Version> for BoundingRange<'a> {
939 fn start_bound(&self) -> Bound<&'a Version> {
940 self.min
941 }
942
943 fn end_bound(&self) -> Bound<&'a Version> {
944 self.max
945 }
946}