mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 02:48:17 +00:00
Avoid clone for WheelMetadataCache
(#500)
This doesn't need to own the underlying data which allows us to remove a number of clones.
This commit is contained in:
parent
3eb0a43995
commit
afda835544
3 changed files with 23 additions and 23 deletions
|
@ -16,19 +16,19 @@ const BUILT_WHEEL_METADATA_CACHE: &str = "built-wheel-metadata-v0";
|
|||
/// See [`WheelMetadataCache::wheel_dir`] for remote wheel metadata caching and
|
||||
/// [`WheelMetadataCache::built_wheel_dir`] for caching of metadata of built source
|
||||
/// distributions.
|
||||
pub enum WheelMetadataCache {
|
||||
pub enum WheelMetadataCache<'a> {
|
||||
/// Either pypi or an alternative index, which we key by index url
|
||||
Index(IndexUrl),
|
||||
Index(&'a IndexUrl),
|
||||
/// A direct url dependency, which we key by url
|
||||
Url(Url),
|
||||
Url(&'a Url),
|
||||
/// A git dependency, which we key by repository url. We use the revision as filename.
|
||||
///
|
||||
/// Note that this variant only exists for source distributions, wheels can't be delivered
|
||||
/// through git.
|
||||
Git(Url),
|
||||
Git(&'a Url),
|
||||
}
|
||||
|
||||
impl WheelMetadataCache {
|
||||
impl<'a> WheelMetadataCache<'a> {
|
||||
fn bucket(&self) -> PathBuf {
|
||||
match self {
|
||||
WheelMetadataCache::Index(IndexUrl::Pypi) => PathBuf::from("pypi"),
|
||||
|
|
|
@ -219,7 +219,7 @@ impl RegistryClient {
|
|||
self.wheel_metadata_no_pep658(
|
||||
&wheel.filename,
|
||||
&wheel.url,
|
||||
WheelMetadataCache::Url(wheel.url.clone()),
|
||||
WheelMetadataCache::Url(&wheel.url),
|
||||
)
|
||||
.await?
|
||||
}
|
||||
|
@ -262,7 +262,7 @@ impl RegistryClient {
|
|||
|
||||
let cache_dir = self
|
||||
.cache
|
||||
.join(WheelMetadataCache::Index(index).wheel_dir());
|
||||
.join(WheelMetadataCache::Index(&index).wheel_dir());
|
||||
let cache_file = format!("{}.json", filename.stem());
|
||||
|
||||
let response_callback = |response: Response| async {
|
||||
|
@ -278,17 +278,17 @@ impl RegistryClient {
|
|||
// If we lack PEP 658 support, try using HTTP range requests to read only the
|
||||
// `.dist-info/METADATA` file from the zip, and if that also fails, download the whole wheel
|
||||
// into the cache and read from there
|
||||
self.wheel_metadata_no_pep658(&filename, &url, WheelMetadataCache::Index(index))
|
||||
self.wheel_metadata_no_pep658(&filename, &url, WheelMetadataCache::Index(&index))
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the wheel metadata if it isn't available in an index through PEP 658
|
||||
async fn wheel_metadata_no_pep658(
|
||||
async fn wheel_metadata_no_pep658<'data>(
|
||||
&self,
|
||||
filename: &WheelFilename,
|
||||
url: &Url,
|
||||
cache_shard: WheelMetadataCache,
|
||||
filename: &'data WheelFilename,
|
||||
url: &'data Url,
|
||||
cache_shard: WheelMetadataCache<'data>,
|
||||
) -> Result<Metadata21, Error> {
|
||||
if self.no_index {
|
||||
return Err(Error::NoIndex(url.to_string()));
|
||||
|
|
|
@ -41,7 +41,7 @@ const GIT_CACHE: &str = "git-v0";
|
|||
#[derive(Debug, Error)]
|
||||
pub enum SourceDistError {
|
||||
// Network error
|
||||
#[error("Failed to parse url '{0}'")]
|
||||
#[error("Failed to parse URL: `{0}`")]
|
||||
UrlParse(String, #[source] url::ParseError),
|
||||
#[error("Git operation failed")]
|
||||
Git(#[source] anyhow::Error),
|
||||
|
@ -158,20 +158,20 @@ impl<'a, T: BuildContext> SourceDistCachedBuilder<'a, T> {
|
|||
source_dist,
|
||||
filename,
|
||||
&url,
|
||||
WheelMetadataCache::Url(url.clone()),
|
||||
WheelMetadataCache::Url(&url),
|
||||
subdirectory.as_deref(),
|
||||
)
|
||||
.await?
|
||||
}
|
||||
SourceDist::Registry(registry_source_dist) => {
|
||||
let url = Url::parse(®istry_source_dist.file.url).map_err(|err| {
|
||||
SourceDistError::UrlParse(registry_source_dist.file.url.to_string(), err)
|
||||
SourceDistError::UrlParse(registry_source_dist.file.url.clone(), err)
|
||||
})?;
|
||||
self.url(
|
||||
source_dist,
|
||||
®istry_source_dist.file.filename,
|
||||
&url,
|
||||
WheelMetadataCache::Index(registry_source_dist.index.clone()),
|
||||
WheelMetadataCache::Index(®istry_source_dist.index),
|
||||
None,
|
||||
)
|
||||
.await?
|
||||
|
@ -223,13 +223,13 @@ impl<'a, T: BuildContext> SourceDistCachedBuilder<'a, T> {
|
|||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
async fn url(
|
||||
async fn url<'data>(
|
||||
&self,
|
||||
source_dist: &SourceDist,
|
||||
filename: &str,
|
||||
url: &Url,
|
||||
cache_shard: WheelMetadataCache,
|
||||
subdirectory: Option<&Path>,
|
||||
source_dist: &'data SourceDist,
|
||||
filename: &'data str,
|
||||
url: &'data Url,
|
||||
cache_shard: WheelMetadataCache<'data>,
|
||||
subdirectory: Option<&'data Path>,
|
||||
) -> Result<BuiltWheelMetadata, SourceDistError> {
|
||||
let cache_dir = self
|
||||
.build_context
|
||||
|
@ -368,7 +368,7 @@ impl<'a, T: BuildContext> SourceDistCachedBuilder<'a, T> {
|
|||
.precise()
|
||||
.expect("Exact commit after checkout")
|
||||
.to_string();
|
||||
let cache_shard = WheelMetadataCache::Git(git_source_dist.url.clone());
|
||||
let cache_shard = WheelMetadataCache::Git(&git_source_dist.url);
|
||||
let cache_dir = self
|
||||
.build_context
|
||||
.cache()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue