Skip to content

Commit d7fb013

Browse files
committed
Include commit_id and requested_revision in direct_url.json
1 parent d454f9c commit d7fb013

File tree

11 files changed

+319
-158
lines changed

11 files changed

+319
-158
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/uv-distribution-types/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ uv-pep508 = { workspace = true }
2828
uv-platform-tags = { workspace = true }
2929
uv-pypi-types = { workspace = true }
3030

31-
anyhow = { workspace = true }
3231
arcstr = { workspace = true }
3332
bitflags = { workspace = true }
3433
fs-err = { workspace = true }

crates/uv-distribution-types/src/cached.rs

Lines changed: 31 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
use std::path::{Path, PathBuf};
22

3-
use anyhow::{anyhow, Result};
4-
53
use uv_cache_info::CacheInfo;
64
use uv_distribution_filename::WheelFilename;
75
use uv_normalize::PackageName;
8-
use uv_pep508::VerbatimUrl;
9-
use uv_pypi_types::{HashDigest, ParsedDirectoryUrl};
6+
use uv_pypi_types::{HashDigest, VerbatimParsedUrl};
107

118
use crate::{
129
BuiltDist, Dist, DistributionMetadata, Hashed, InstalledMetadata, InstalledVersion, Name,
@@ -33,10 +30,8 @@ pub struct CachedRegistryDist {
3330
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
3431
pub struct CachedDirectUrlDist {
3532
pub filename: WheelFilename,
36-
pub url: VerbatimUrl,
33+
pub url: VerbatimParsedUrl,
3734
pub path: PathBuf,
38-
pub editable: bool,
39-
pub r#virtual: bool,
4035
pub hashes: Vec<HashDigest>,
4136
pub cache_info: CacheInfo,
4237
}
@@ -59,21 +54,23 @@ impl CachedDist {
5954
}),
6055
Dist::Built(BuiltDist::DirectUrl(dist)) => Self::Url(CachedDirectUrlDist {
6156
filename,
62-
url: dist.url,
57+
url: VerbatimParsedUrl {
58+
parsed_url: dist.parsed_url(),
59+
verbatim: dist.url,
60+
},
6361
hashes,
6462
cache_info,
6563
path,
66-
editable: false,
67-
r#virtual: false,
6864
}),
6965
Dist::Built(BuiltDist::Path(dist)) => Self::Url(CachedDirectUrlDist {
7066
filename,
71-
url: dist.url,
67+
url: VerbatimParsedUrl {
68+
parsed_url: dist.parsed_url(),
69+
verbatim: dist.url,
70+
},
7271
hashes,
7372
cache_info,
7473
path,
75-
editable: false,
76-
r#virtual: false,
7774
}),
7875
Dist::Source(SourceDist::Registry(_dist)) => Self::Registry(CachedRegistryDist {
7976
filename,
@@ -83,39 +80,43 @@ impl CachedDist {
8380
}),
8481
Dist::Source(SourceDist::DirectUrl(dist)) => Self::Url(CachedDirectUrlDist {
8582
filename,
86-
url: dist.url,
83+
url: VerbatimParsedUrl {
84+
parsed_url: dist.parsed_url(),
85+
verbatim: dist.url,
86+
},
8787
hashes,
8888
cache_info,
8989
path,
90-
editable: false,
91-
r#virtual: false,
9290
}),
9391
Dist::Source(SourceDist::Git(dist)) => Self::Url(CachedDirectUrlDist {
9492
filename,
95-
url: dist.url,
93+
url: VerbatimParsedUrl {
94+
parsed_url: dist.parsed_url(),
95+
verbatim: dist.url,
96+
},
9697
hashes,
9798
cache_info,
9899
path,
99-
editable: false,
100-
r#virtual: false,
101100
}),
102101
Dist::Source(SourceDist::Path(dist)) => Self::Url(CachedDirectUrlDist {
103102
filename,
104-
url: dist.url,
103+
url: VerbatimParsedUrl {
104+
parsed_url: dist.parsed_url(),
105+
verbatim: dist.url,
106+
},
105107
hashes,
106108
cache_info,
107109
path,
108-
editable: false,
109-
r#virtual: false,
110110
}),
111111
Dist::Source(SourceDist::Directory(dist)) => Self::Url(CachedDirectUrlDist {
112112
filename,
113-
url: dist.url,
113+
url: VerbatimParsedUrl {
114+
parsed_url: dist.parsed_url(),
115+
verbatim: dist.url,
116+
},
114117
hashes,
115118
cache_info,
116119
path,
117-
editable: dist.editable,
118-
r#virtual: dist.r#virtual,
119120
}),
120121
}
121122
}
@@ -137,26 +138,10 @@ impl CachedDist {
137138
}
138139

139140
/// Return the [`ParsedUrl`] of the distribution, if it exists.
140-
pub fn parsed_url(&self) -> Result<Option<ParsedUrl>> {
141+
pub fn parsed_url(&self) -> Option<&ParsedUrl> {
141142
match self {
142-
Self::Registry(_) => Ok(None),
143-
Self::Url(dist) => {
144-
if dist.editable {
145-
assert_eq!(dist.url.scheme(), "file", "{}", dist.url);
146-
let path = dist
147-
.url
148-
.to_file_path()
149-
.map_err(|()| anyhow!("Invalid path in file URL"))?;
150-
Ok(Some(ParsedUrl::Directory(ParsedDirectoryUrl {
151-
url: dist.url.raw().clone(),
152-
install_path: path,
153-
editable: dist.editable,
154-
r#virtual: dist.r#virtual,
155-
})))
156-
} else {
157-
Ok(Some(ParsedUrl::try_from(dist.url.to_url())?))
158-
}
159-
}
143+
Self::Registry(_) => None,
144+
Self::Url(dist) => Some(&dist.url.parsed_url),
160145
}
161146
}
162147

@@ -175,27 +160,6 @@ impl Hashed for CachedRegistryDist {
175160
}
176161
}
177162

178-
impl CachedDirectUrlDist {
179-
/// Initialize a [`CachedDirectUrlDist`] from a [`WheelFilename`], [`url::Url`], and [`Path`].
180-
pub fn from_url(
181-
filename: WheelFilename,
182-
url: VerbatimUrl,
183-
hashes: Vec<HashDigest>,
184-
cache_info: CacheInfo,
185-
path: PathBuf,
186-
) -> Self {
187-
Self {
188-
filename,
189-
url,
190-
hashes,
191-
cache_info,
192-
path,
193-
editable: false,
194-
r#virtual: false,
195-
}
196-
}
197-
}
198-
199163
impl Name for CachedRegistryDist {
200164
fn name(&self) -> &PackageName {
201165
&self.filename.name
@@ -225,7 +189,7 @@ impl DistributionMetadata for CachedRegistryDist {
225189

226190
impl DistributionMetadata for CachedDirectUrlDist {
227191
fn version_or_url(&self) -> VersionOrUrlRef {
228-
VersionOrUrlRef::Url(&self.url)
192+
VersionOrUrlRef::Url(&self.url.verbatim)
229193
}
230194
}
231195

@@ -246,7 +210,7 @@ impl InstalledMetadata for CachedRegistryDist {
246210

247211
impl InstalledMetadata for CachedDirectUrlDist {
248212
fn installed_version(&self) -> InstalledVersion {
249-
InstalledVersion::Url(&self.url, &self.filename.version)
213+
InstalledVersion::Url(&self.url.verbatim, &self.filename.version)
250214
}
251215
}
252216

crates/uv-distribution-types/src/lib.rs

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ use uv_git::GitUrl;
4747
use uv_normalize::PackageName;
4848
use uv_pep440::Version;
4949
use uv_pep508::{Pep508Url, VerbatimUrl};
50-
use uv_pypi_types::{ParsedUrl, VerbatimParsedUrl};
50+
use uv_pypi_types::{
51+
ParsedArchiveUrl, ParsedDirectoryUrl, ParsedGitUrl, ParsedPathUrl, ParsedUrl, VerbatimParsedUrl,
52+
};
5153

5254
pub use crate::annotation::*;
5355
pub use crate::any::*;
@@ -662,6 +664,74 @@ impl RegistryBuiltDist {
662664
}
663665
}
664666

667+
impl DirectUrlBuiltDist {
668+
/// Return the [`ParsedUrl`] for the distribution.
669+
pub fn parsed_url(&self) -> ParsedUrl {
670+
ParsedUrl::Archive(ParsedArchiveUrl::from_source(
671+
(*self.location).clone(),
672+
None,
673+
DistExtension::Wheel,
674+
))
675+
}
676+
}
677+
678+
impl PathBuiltDist {
679+
/// Return the [`ParsedUrl`] for the distribution.
680+
pub fn parsed_url(&self) -> ParsedUrl {
681+
ParsedUrl::Path(ParsedPathUrl::from_source(
682+
self.install_path.clone(),
683+
DistExtension::Wheel,
684+
self.url.to_url(),
685+
))
686+
}
687+
}
688+
689+
impl PathSourceDist {
690+
/// Return the [`ParsedUrl`] for the distribution.
691+
pub fn parsed_url(&self) -> ParsedUrl {
692+
ParsedUrl::Path(ParsedPathUrl::from_source(
693+
self.install_path.clone(),
694+
DistExtension::Source(self.ext),
695+
self.url.to_url(),
696+
))
697+
}
698+
}
699+
700+
impl DirectUrlSourceDist {
701+
/// Return the [`ParsedUrl`] for the distribution.
702+
pub fn parsed_url(&self) -> ParsedUrl {
703+
ParsedUrl::Archive(ParsedArchiveUrl::from_source(
704+
(*self.location).clone(),
705+
self.subdirectory.clone(),
706+
DistExtension::Source(self.ext),
707+
))
708+
}
709+
}
710+
711+
impl GitSourceDist {
712+
/// Return the [`ParsedUrl`] for the distribution.
713+
pub fn parsed_url(&self) -> ParsedUrl {
714+
ParsedUrl::Git(ParsedGitUrl::from_source(
715+
self.git.repository().clone(),
716+
self.git.reference().clone(),
717+
self.git.precise(),
718+
self.subdirectory.clone(),
719+
))
720+
}
721+
}
722+
723+
impl DirectorySourceDist {
724+
/// Return the [`ParsedUrl`] for the distribution.
725+
pub fn parsed_url(&self) -> ParsedUrl {
726+
ParsedUrl::Directory(ParsedDirectoryUrl::from_source(
727+
self.install_path.clone(),
728+
self.editable,
729+
self.r#virtual,
730+
self.url.to_url(),
731+
))
732+
}
733+
}
734+
665735
impl Name for RegistryBuiltWheel {
666736
fn name(&self) -> &PackageName {
667737
&self.filename.name

crates/uv-distribution/src/index/cached_wheel.rs

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
use std::path::Path;
22

3-
use crate::archive::Archive;
4-
use crate::{HttpArchivePointer, LocalArchivePointer};
53
use uv_cache::{Cache, CacheBucket, CacheEntry};
64
use uv_cache_info::CacheInfo;
75
use uv_distribution_filename::WheelFilename;
8-
use uv_distribution_types::{CachedDirectUrlDist, CachedRegistryDist, Hashed};
9-
use uv_pep508::VerbatimUrl;
10-
use uv_pypi_types::HashDigest;
6+
use uv_distribution_types::{
7+
CachedDirectUrlDist, CachedRegistryDist, DirectUrlSourceDist, DirectorySourceDist,
8+
GitSourceDist, Hashed, PathSourceDist,
9+
};
10+
use uv_pypi_types::{HashDigest, VerbatimParsedUrl};
11+
12+
use crate::archive::Archive;
13+
use crate::{HttpArchivePointer, LocalArchivePointer};
1114

1215
#[derive(Debug, Clone)]
1316
pub struct CachedWheel {
@@ -53,40 +56,61 @@ impl CachedWheel {
5356
}
5457
}
5558

56-
/// Convert a [`CachedWheel`] into a [`CachedDirectUrlDist`].
57-
pub fn into_url_dist(self, url: VerbatimUrl) -> CachedDirectUrlDist {
59+
/// Convert a [`CachedWheel`] into a [`CachedDirectUrlDist`] by merging in the given
60+
/// [`DirectUrlSourceDist`].
61+
pub fn into_url_dist(self, dist: &DirectUrlSourceDist) -> CachedDirectUrlDist {
62+
CachedDirectUrlDist {
63+
filename: self.filename,
64+
url: VerbatimParsedUrl {
65+
parsed_url: dist.parsed_url(),
66+
verbatim: dist.url.clone(),
67+
},
68+
path: self.entry.into_path_buf(),
69+
hashes: self.hashes,
70+
cache_info: self.cache_info,
71+
}
72+
}
73+
74+
/// Convert a [`CachedWheel`] into a [`CachedDirectUrlDist`] by merging in the given
75+
/// [`PathSourceDist`].
76+
pub fn into_path_dist(self, dist: &PathSourceDist) -> CachedDirectUrlDist {
5877
CachedDirectUrlDist {
5978
filename: self.filename,
60-
url,
79+
url: VerbatimParsedUrl {
80+
parsed_url: dist.parsed_url(),
81+
verbatim: dist.url.clone(),
82+
},
6183
path: self.entry.into_path_buf(),
62-
editable: false,
63-
r#virtual: false,
6484
hashes: self.hashes,
6585
cache_info: self.cache_info,
6686
}
6787
}
6888

69-
/// Convert a [`CachedWheel`] into an editable [`CachedDirectUrlDist`].
70-
pub fn into_editable(self, url: VerbatimUrl) -> CachedDirectUrlDist {
89+
/// Convert a [`CachedWheel`] into a [`CachedDirectUrlDist`] by merging in the given
90+
/// [`DirectorySourceDist`].
91+
pub fn into_directory_dist(self, dist: &DirectorySourceDist) -> CachedDirectUrlDist {
7192
CachedDirectUrlDist {
7293
filename: self.filename,
73-
url,
94+
url: VerbatimParsedUrl {
95+
parsed_url: dist.parsed_url(),
96+
verbatim: dist.url.clone(),
97+
},
7498
path: self.entry.into_path_buf(),
75-
editable: true,
76-
r#virtual: false,
7799
hashes: self.hashes,
78100
cache_info: self.cache_info,
79101
}
80102
}
81103

82-
/// Convert a [`CachedWheel`] into an editable [`CachedDirectUrlDist`].
83-
pub fn into_virtual(self, url: VerbatimUrl) -> CachedDirectUrlDist {
104+
/// Convert a [`CachedWheel`] into a [`CachedDirectUrlDist`] by merging in the given
105+
/// [`GitSourceDist`].
106+
pub fn into_git_dist(self, dist: &GitSourceDist) -> CachedDirectUrlDist {
84107
CachedDirectUrlDist {
85108
filename: self.filename,
86-
url,
109+
url: VerbatimParsedUrl {
110+
parsed_url: dist.parsed_url(),
111+
verbatim: dist.url.clone(),
112+
},
87113
path: self.entry.into_path_buf(),
88-
editable: false,
89-
r#virtual: true,
90114
hashes: self.hashes,
91115
cache_info: self.cache_info,
92116
}

0 commit comments

Comments
 (0)