Remove FileLocation::Path variant (#6577)

## Summary

This is redundant now that we support `file://` URLs.
This commit is contained in:
Charlie Marsh 2024-08-24 07:52:43 -04:00 committed by GitHub
parent 2f94422484
commit 1eb97c91fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 7 additions and 64 deletions

View file

@ -79,8 +79,6 @@ pub enum FileLocation {
RelativeUrl(String, String),
/// Absolute URL.
AbsoluteUrl(UrlString),
/// Absolute path to a file.
Path(#[with(rkyv::with::AsString)] PathBuf),
}
impl FileLocation {
@ -110,15 +108,6 @@ impl FileLocation {
Ok(joined)
}
FileLocation::AbsoluteUrl(ref absolute) => Ok(absolute.to_url()),
FileLocation::Path(ref path) => {
let path = path
.to_str()
.ok_or_else(|| ToUrlError::PathNotUtf8 { path: path.clone() })?;
let url = Url::from_file_path(path).map_err(|()| ToUrlError::InvalidPath {
path: path.to_string(),
})?;
Ok(url)
}
}
}
@ -129,7 +118,7 @@ impl FileLocation {
pub fn to_url_string(&self) -> Result<UrlString, ToUrlError> {
match *self {
FileLocation::AbsoluteUrl(ref absolute) => Ok(absolute.clone()),
_ => Ok(self.to_url()?.into()),
FileLocation::RelativeUrl(_, _) => Ok(self.to_url()?.into()),
}
}
}
@ -139,7 +128,6 @@ impl Display for FileLocation {
match self {
Self::RelativeUrl(_base, url) => Display::fmt(&url, f),
Self::AbsoluteUrl(url) => Display::fmt(&url.0, f),
Self::Path(path) => Display::fmt(&path.display(), f),
}
}
}

View file

@ -1019,7 +1019,6 @@ impl Identifier for FileLocation {
DistributionId::RelativeUrl(base.to_string(), url.to_string())
}
Self::AbsoluteUrl(url) => DistributionId::AbsoluteUrl(url.to_string()),
Self::Path(path) => path.distribution_id(),
}
}
@ -1029,7 +1028,6 @@ impl Identifier for FileLocation {
ResourceId::RelativeUrl(base.to_string(), url.to_string())
}
Self::AbsoluteUrl(url) => ResourceId::AbsoluteUrl(url.to_string()),
Self::Path(path) => path.resource_id(),
}
}
}

View file

@ -6,7 +6,7 @@ use tracing::{debug, info_span, warn, Instrument};
use url::Url;
use distribution_filename::DistFilename;
use distribution_types::{File, FileLocation, FlatIndexLocation, IndexUrl};
use distribution_types::{File, FileLocation, FlatIndexLocation, IndexUrl, UrlString};
use uv_cache::{Cache, CacheBucket};
use crate::cached_client::{CacheControl, CachedClientError};
@ -254,6 +254,9 @@ impl<'a> FlatIndexClient<'a> {
continue;
};
// SAFETY: The index path is itself constructed from a URL.
let url = Url::from_file_path(entry.path()).unwrap();
let file = File {
dist_info_metadata: false,
filename: filename.to_string(),
@ -261,7 +264,7 @@ impl<'a> FlatIndexClient<'a> {
requires_python: None,
size: None,
upload_time_utc_ms: None,
url: FileLocation::Path(entry.path().clone()),
url: FileLocation::AbsoluteUrl(UrlString::from(url)),
yanked: None,
};

View file

@ -427,7 +427,6 @@ impl RegistryClient {
WheelLocation::Url(url)
}
}
FileLocation::Path(path) => WheelLocation::Path(path.clone()),
};
match location {

View file

@ -151,16 +151,6 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
pypi_types::base_url_join_relative(base, url)?
}
FileLocation::AbsoluteUrl(url) => url.to_url(),
FileLocation::Path(path) => {
let cache_entry = self.build_context.cache().entry(
CacheBucket::Wheels,
WheelCache::Index(&wheel.index).wheel_dir(wheel.name().as_ref()),
wheel.filename.stem(),
);
return self
.load_wheel(path, &wheel.filename, cache_entry, dist, hashes)
.await;
}
};
// Create a cache entry for the wheel.

View file

@ -100,24 +100,6 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
pypi_types::base_url_join_relative(base, url)?
}
FileLocation::AbsoluteUrl(url) => url.to_url(),
FileLocation::Path(path) => {
let url = Url::from_file_path(path)
.map_err(|()| Error::RelativePath(path.clone()))?;
return self
.archive(
source,
&PathSourceUrl {
url: &url,
path: Cow::Borrowed(path),
ext: dist.ext,
},
&cache_shard,
tags,
hashes,
)
.boxed_local()
.await;
}
};
// If the URL is a file URL, use the local path directly.
@ -277,23 +259,6 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
pypi_types::base_url_join_relative(base, url)?
}
FileLocation::AbsoluteUrl(url) => url.to_url(),
FileLocation::Path(path) => {
let url = Url::from_file_path(path)
.map_err(|()| Error::RelativePath(path.clone()))?;
return self
.archive_metadata(
source,
&PathSourceUrl {
url: &url,
path: Cow::Borrowed(path),
ext: dist.ext,
},
&cache_shard,
hashes,
)
.boxed_local()
.await;
}
};
// If the URL is a file URL, use the local path directly.

View file

@ -2856,7 +2856,7 @@ impl<'de> serde::Deserialize<'de> for Hash {
fn normalize_file_location(location: &FileLocation) -> Result<UrlString, ToUrlError> {
match location {
FileLocation::AbsoluteUrl(ref absolute) => Ok(absolute.as_base_url()),
_ => Ok(normalize_url(location.to_url()?)),
FileLocation::RelativeUrl(_, _) => Ok(normalize_url(location.to_url()?)),
}
}