mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-03 07:14:35 +00:00
Remove FileLocation::Path
variant (#6577)
## Summary This is redundant now that we support `file://` URLs.
This commit is contained in:
parent
2f94422484
commit
1eb97c91fd
7 changed files with 7 additions and 64 deletions
|
@ -79,8 +79,6 @@ pub enum FileLocation {
|
||||||
RelativeUrl(String, String),
|
RelativeUrl(String, String),
|
||||||
/// Absolute URL.
|
/// Absolute URL.
|
||||||
AbsoluteUrl(UrlString),
|
AbsoluteUrl(UrlString),
|
||||||
/// Absolute path to a file.
|
|
||||||
Path(#[with(rkyv::with::AsString)] PathBuf),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FileLocation {
|
impl FileLocation {
|
||||||
|
@ -110,15 +108,6 @@ impl FileLocation {
|
||||||
Ok(joined)
|
Ok(joined)
|
||||||
}
|
}
|
||||||
FileLocation::AbsoluteUrl(ref absolute) => Ok(absolute.to_url()),
|
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> {
|
pub fn to_url_string(&self) -> Result<UrlString, ToUrlError> {
|
||||||
match *self {
|
match *self {
|
||||||
FileLocation::AbsoluteUrl(ref absolute) => Ok(absolute.clone()),
|
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 {
|
match self {
|
||||||
Self::RelativeUrl(_base, url) => Display::fmt(&url, f),
|
Self::RelativeUrl(_base, url) => Display::fmt(&url, f),
|
||||||
Self::AbsoluteUrl(url) => Display::fmt(&url.0, f),
|
Self::AbsoluteUrl(url) => Display::fmt(&url.0, f),
|
||||||
Self::Path(path) => Display::fmt(&path.display(), f),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1019,7 +1019,6 @@ impl Identifier for FileLocation {
|
||||||
DistributionId::RelativeUrl(base.to_string(), url.to_string())
|
DistributionId::RelativeUrl(base.to_string(), url.to_string())
|
||||||
}
|
}
|
||||||
Self::AbsoluteUrl(url) => DistributionId::AbsoluteUrl(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())
|
ResourceId::RelativeUrl(base.to_string(), url.to_string())
|
||||||
}
|
}
|
||||||
Self::AbsoluteUrl(url) => ResourceId::AbsoluteUrl(url.to_string()),
|
Self::AbsoluteUrl(url) => ResourceId::AbsoluteUrl(url.to_string()),
|
||||||
Self::Path(path) => path.resource_id(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use tracing::{debug, info_span, warn, Instrument};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use distribution_filename::DistFilename;
|
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 uv_cache::{Cache, CacheBucket};
|
||||||
|
|
||||||
use crate::cached_client::{CacheControl, CachedClientError};
|
use crate::cached_client::{CacheControl, CachedClientError};
|
||||||
|
@ -254,6 +254,9 @@ impl<'a> FlatIndexClient<'a> {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// SAFETY: The index path is itself constructed from a URL.
|
||||||
|
let url = Url::from_file_path(entry.path()).unwrap();
|
||||||
|
|
||||||
let file = File {
|
let file = File {
|
||||||
dist_info_metadata: false,
|
dist_info_metadata: false,
|
||||||
filename: filename.to_string(),
|
filename: filename.to_string(),
|
||||||
|
@ -261,7 +264,7 @@ impl<'a> FlatIndexClient<'a> {
|
||||||
requires_python: None,
|
requires_python: None,
|
||||||
size: None,
|
size: None,
|
||||||
upload_time_utc_ms: None,
|
upload_time_utc_ms: None,
|
||||||
url: FileLocation::Path(entry.path().clone()),
|
url: FileLocation::AbsoluteUrl(UrlString::from(url)),
|
||||||
yanked: None,
|
yanked: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -427,7 +427,6 @@ impl RegistryClient {
|
||||||
WheelLocation::Url(url)
|
WheelLocation::Url(url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FileLocation::Path(path) => WheelLocation::Path(path.clone()),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
match location {
|
match location {
|
||||||
|
|
|
@ -151,16 +151,6 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
|
||||||
pypi_types::base_url_join_relative(base, url)?
|
pypi_types::base_url_join_relative(base, url)?
|
||||||
}
|
}
|
||||||
FileLocation::AbsoluteUrl(url) => url.to_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.
|
// Create a cache entry for the wheel.
|
||||||
|
|
|
@ -100,24 +100,6 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
|
||||||
pypi_types::base_url_join_relative(base, url)?
|
pypi_types::base_url_join_relative(base, url)?
|
||||||
}
|
}
|
||||||
FileLocation::AbsoluteUrl(url) => url.to_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.
|
// 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)?
|
pypi_types::base_url_join_relative(base, url)?
|
||||||
}
|
}
|
||||||
FileLocation::AbsoluteUrl(url) => url.to_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.
|
// If the URL is a file URL, use the local path directly.
|
||||||
|
|
|
@ -2856,7 +2856,7 @@ impl<'de> serde::Deserialize<'de> for Hash {
|
||||||
fn normalize_file_location(location: &FileLocation) -> Result<UrlString, ToUrlError> {
|
fn normalize_file_location(location: &FileLocation) -> Result<UrlString, ToUrlError> {
|
||||||
match location {
|
match location {
|
||||||
FileLocation::AbsoluteUrl(ref absolute) => Ok(absolute.as_base_url()),
|
FileLocation::AbsoluteUrl(ref absolute) => Ok(absolute.as_base_url()),
|
||||||
_ => Ok(normalize_url(location.to_url()?)),
|
FileLocation::RelativeUrl(_, _) => Ok(normalize_url(location.to_url()?)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue