mirror of
https://github.com/astral-sh/uv.git
synced 2025-09-28 04:54:47 +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
|
/// See [`WheelMetadataCache::wheel_dir`] for remote wheel metadata caching and
|
||||||
/// [`WheelMetadataCache::built_wheel_dir`] for caching of metadata of built source
|
/// [`WheelMetadataCache::built_wheel_dir`] for caching of metadata of built source
|
||||||
/// distributions.
|
/// distributions.
|
||||||
pub enum WheelMetadataCache {
|
pub enum WheelMetadataCache<'a> {
|
||||||
/// Either pypi or an alternative index, which we key by index url
|
/// 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
|
/// 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.
|
/// 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
|
/// Note that this variant only exists for source distributions, wheels can't be delivered
|
||||||
/// through git.
|
/// through git.
|
||||||
Git(Url),
|
Git(&'a Url),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WheelMetadataCache {
|
impl<'a> WheelMetadataCache<'a> {
|
||||||
fn bucket(&self) -> PathBuf {
|
fn bucket(&self) -> PathBuf {
|
||||||
match self {
|
match self {
|
||||||
WheelMetadataCache::Index(IndexUrl::Pypi) => PathBuf::from("pypi"),
|
WheelMetadataCache::Index(IndexUrl::Pypi) => PathBuf::from("pypi"),
|
||||||
|
|
|
@ -219,7 +219,7 @@ impl RegistryClient {
|
||||||
self.wheel_metadata_no_pep658(
|
self.wheel_metadata_no_pep658(
|
||||||
&wheel.filename,
|
&wheel.filename,
|
||||||
&wheel.url,
|
&wheel.url,
|
||||||
WheelMetadataCache::Url(wheel.url.clone()),
|
WheelMetadataCache::Url(&wheel.url),
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
}
|
}
|
||||||
|
@ -262,7 +262,7 @@ impl RegistryClient {
|
||||||
|
|
||||||
let cache_dir = self
|
let cache_dir = self
|
||||||
.cache
|
.cache
|
||||||
.join(WheelMetadataCache::Index(index).wheel_dir());
|
.join(WheelMetadataCache::Index(&index).wheel_dir());
|
||||||
let cache_file = format!("{}.json", filename.stem());
|
let cache_file = format!("{}.json", filename.stem());
|
||||||
|
|
||||||
let response_callback = |response: Response| async {
|
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
|
// 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
|
// `.dist-info/METADATA` file from the zip, and if that also fails, download the whole wheel
|
||||||
// into the cache and read from there
|
// 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
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the wheel metadata if it isn't available in an index through PEP 658
|
/// 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,
|
&self,
|
||||||
filename: &WheelFilename,
|
filename: &'data WheelFilename,
|
||||||
url: &Url,
|
url: &'data Url,
|
||||||
cache_shard: WheelMetadataCache,
|
cache_shard: WheelMetadataCache<'data>,
|
||||||
) -> Result<Metadata21, Error> {
|
) -> Result<Metadata21, Error> {
|
||||||
if self.no_index {
|
if self.no_index {
|
||||||
return Err(Error::NoIndex(url.to_string()));
|
return Err(Error::NoIndex(url.to_string()));
|
||||||
|
|
|
@ -41,7 +41,7 @@ const GIT_CACHE: &str = "git-v0";
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum SourceDistError {
|
pub enum SourceDistError {
|
||||||
// Network error
|
// Network error
|
||||||
#[error("Failed to parse url '{0}'")]
|
#[error("Failed to parse URL: `{0}`")]
|
||||||
UrlParse(String, #[source] url::ParseError),
|
UrlParse(String, #[source] url::ParseError),
|
||||||
#[error("Git operation failed")]
|
#[error("Git operation failed")]
|
||||||
Git(#[source] anyhow::Error),
|
Git(#[source] anyhow::Error),
|
||||||
|
@ -158,20 +158,20 @@ impl<'a, T: BuildContext> SourceDistCachedBuilder<'a, T> {
|
||||||
source_dist,
|
source_dist,
|
||||||
filename,
|
filename,
|
||||||
&url,
|
&url,
|
||||||
WheelMetadataCache::Url(url.clone()),
|
WheelMetadataCache::Url(&url),
|
||||||
subdirectory.as_deref(),
|
subdirectory.as_deref(),
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
}
|
}
|
||||||
SourceDist::Registry(registry_source_dist) => {
|
SourceDist::Registry(registry_source_dist) => {
|
||||||
let url = Url::parse(®istry_source_dist.file.url).map_err(|err| {
|
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(
|
self.url(
|
||||||
source_dist,
|
source_dist,
|
||||||
®istry_source_dist.file.filename,
|
®istry_source_dist.file.filename,
|
||||||
&url,
|
&url,
|
||||||
WheelMetadataCache::Index(registry_source_dist.index.clone()),
|
WheelMetadataCache::Index(®istry_source_dist.index),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
|
@ -223,13 +223,13 @@ impl<'a, T: BuildContext> SourceDistCachedBuilder<'a, T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
async fn url(
|
async fn url<'data>(
|
||||||
&self,
|
&self,
|
||||||
source_dist: &SourceDist,
|
source_dist: &'data SourceDist,
|
||||||
filename: &str,
|
filename: &'data str,
|
||||||
url: &Url,
|
url: &'data Url,
|
||||||
cache_shard: WheelMetadataCache,
|
cache_shard: WheelMetadataCache<'data>,
|
||||||
subdirectory: Option<&Path>,
|
subdirectory: Option<&'data Path>,
|
||||||
) -> Result<BuiltWheelMetadata, SourceDistError> {
|
) -> Result<BuiltWheelMetadata, SourceDistError> {
|
||||||
let cache_dir = self
|
let cache_dir = self
|
||||||
.build_context
|
.build_context
|
||||||
|
@ -368,7 +368,7 @@ impl<'a, T: BuildContext> SourceDistCachedBuilder<'a, T> {
|
||||||
.precise()
|
.precise()
|
||||||
.expect("Exact commit after checkout")
|
.expect("Exact commit after checkout")
|
||||||
.to_string();
|
.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
|
let cache_dir = self
|
||||||
.build_context
|
.build_context
|
||||||
.cache()
|
.cache()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue