uv_distribution/
download.rs1use std::path::Path;
2
3use uv_cache_info::CacheInfo;
4use uv_distribution_filename::WheelFilename;
5use uv_distribution_types::{BuildInfo, CachedDist, Dist, Hashed};
6use uv_metadata::read_flat_wheel_metadata;
7use uv_pypi_types::{HashDigest, HashDigests, ResolutionMetadata};
8
9use crate::Error;
10
11#[derive(Debug, Clone)]
13pub struct LocalWheel {
14 pub(crate) dist: Dist,
16 pub(crate) filename: WheelFilename,
18 pub(crate) archive: Box<Path>,
21 pub(crate) cache: CacheInfo,
23 pub(crate) build: Option<BuildInfo>,
25 pub(crate) hashes: HashDigests,
27}
28
29impl LocalWheel {
30 fn remote(&self) -> &Dist {
32 &self.dist
33 }
34
35 pub(crate) fn metadata(&self) -> Result<ResolutionMetadata, Error> {
37 read_flat_wheel_metadata(&self.filename, &self.archive)
38 .map_err(|err| Error::WheelMetadata(self.archive.to_path_buf(), Box::new(err)))
39 }
40}
41
42impl Hashed for LocalWheel {
43 fn hashes(&self) -> &[HashDigest] {
44 self.hashes.as_slice()
45 }
46}
47
48impl From<LocalWheel> for CachedDist {
50 fn from(wheel: LocalWheel) -> Self {
51 Self::from_remote(
52 wheel.dist,
53 wheel.filename,
54 wheel.hashes,
55 wheel.cache,
56 wheel.build,
57 wheel.archive,
58 )
59 }
60}
61
62impl std::fmt::Display for LocalWheel {
63 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
64 write!(f, "{}", self.remote())
65 }
66}