mirror of
https://github.com/astral-sh/uv.git
synced 2025-09-28 21:14:47 +00:00
Use a standalone error type for --find-links
registry (#936)
This commit is contained in:
parent
e71e3e8dd1
commit
2a69b273ce
4 changed files with 23 additions and 17 deletions
|
@ -70,7 +70,7 @@ enum VenvError {
|
||||||
|
|
||||||
#[error("Failed to resolve `--find-links` entry")]
|
#[error("Failed to resolve `--find-links` entry")]
|
||||||
#[diagnostic(code(puffin::venv::flat_index))]
|
#[diagnostic(code(puffin::venv::flat_index))]
|
||||||
FlatIndexError(#[source] puffin_client::Error),
|
FlatIndexError(#[source] puffin_client::FlatIndexError),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a virtual environment.
|
/// Create a virtual environment.
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
use std::io;
|
|
||||||
|
|
||||||
use async_http_range_reader::AsyncHttpRangeReaderError;
|
use async_http_range_reader::AsyncHttpRangeReaderError;
|
||||||
use async_zip::error::ZipError;
|
use async_zip::error::ZipError;
|
||||||
use thiserror::Error;
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::html;
|
|
||||||
use distribution_filename::{WheelFilename, WheelFilenameError};
|
use distribution_filename::{WheelFilename, WheelFilenameError};
|
||||||
use puffin_normalize::PackageName;
|
use puffin_normalize::PackageName;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
use crate::html;
|
||||||
|
|
||||||
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// An invalid URL was provided.
|
/// An invalid URL was provided.
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
|
@ -72,10 +70,10 @@ pub enum Error {
|
||||||
Zip(WheelFilename, #[source] ZipError),
|
Zip(WheelFilename, #[source] ZipError),
|
||||||
|
|
||||||
#[error("Failed to write to the client cache")]
|
#[error("Failed to write to the client cache")]
|
||||||
CacheWrite(#[source] io::Error),
|
CacheWrite(#[source] std::io::Error),
|
||||||
|
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Io(#[from] io::Error),
|
Io(#[from] std::io::Error),
|
||||||
|
|
||||||
#[error("Cache deserialization failed")]
|
#[error("Cache deserialization failed")]
|
||||||
Decode(#[from] rmp_serde::decode::Error),
|
Decode(#[from] rmp_serde::decode::Error),
|
||||||
|
@ -95,9 +93,6 @@ pub enum Error {
|
||||||
|
|
||||||
#[error("Unsupported `Content-Type` \"{1}\" for {0}. Expected JSON or HTML.")]
|
#[error("Unsupported `Content-Type` \"{1}\" for {0}. Expected JSON or HTML.")]
|
||||||
UnsupportedMediaType(Url, String),
|
UnsupportedMediaType(Url, String),
|
||||||
|
|
||||||
#[error("Failed to read find links directory")]
|
|
||||||
FindLinks(#[source] io::Error),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
|
|
|
@ -22,6 +22,15 @@ use pypi_types::Hashes;
|
||||||
use crate::html::SimpleHtml;
|
use crate::html::SimpleHtml;
|
||||||
use crate::{Error, RegistryClient};
|
use crate::{Error, RegistryClient};
|
||||||
|
|
||||||
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
pub enum FlatIndexError {
|
||||||
|
#[error("Failed to read `--find-links` directory: {0}")]
|
||||||
|
FindLinksDirectory(PathBuf, #[source] std::io::Error),
|
||||||
|
|
||||||
|
#[error("Failed to read `--find-links` URL: {0}")]
|
||||||
|
FindLinksUrl(Url, #[source] Error),
|
||||||
|
}
|
||||||
|
|
||||||
type FlatIndexEntry = (DistFilename, File, IndexUrl);
|
type FlatIndexEntry = (DistFilename, File, IndexUrl);
|
||||||
|
|
||||||
/// A client for reading distributions from `--find-links` entries (either local directories or
|
/// A client for reading distributions from `--find-links` entries (either local directories or
|
||||||
|
@ -43,15 +52,17 @@ impl<'a> FlatIndexClient<'a> {
|
||||||
pub async fn fetch(
|
pub async fn fetch(
|
||||||
&self,
|
&self,
|
||||||
indexes: impl Iterator<Item = &FlatIndexLocation>,
|
indexes: impl Iterator<Item = &FlatIndexLocation>,
|
||||||
) -> Result<Vec<FlatIndexEntry>, Error> {
|
) -> Result<Vec<FlatIndexEntry>, FlatIndexError> {
|
||||||
let mut dists = Vec::new();
|
let mut dists = Vec::new();
|
||||||
// TODO(konstin): Parallelize reads over flat indexes.
|
// TODO(konstin): Parallelize reads over flat indexes.
|
||||||
for flat_index in indexes {
|
for flat_index in indexes {
|
||||||
let index_dists = match flat_index {
|
let index_dists = match flat_index {
|
||||||
FlatIndexLocation::Path(path) => {
|
FlatIndexLocation::Path(path) => Self::read_from_directory(path)
|
||||||
Self::read_from_directory(path).map_err(Error::FindLinks)?
|
.map_err(|err| FlatIndexError::FindLinksDirectory(path.clone(), err))?,
|
||||||
}
|
FlatIndexLocation::Url(url) => self
|
||||||
FlatIndexLocation::Url(url) => self.read_from_url(url).await?,
|
.read_from_url(url)
|
||||||
|
.await
|
||||||
|
.map_err(|err| FlatIndexError::FindLinksUrl(url.clone(), err))?,
|
||||||
};
|
};
|
||||||
if index_dists.is_empty() {
|
if index_dists.is_empty() {
|
||||||
warn!("No packages found in `--find-links` entry: {}", flat_index);
|
warn!("No packages found in `--find-links` entry: {}", flat_index);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
pub use cached_client::{CachedClient, CachedClientError, DataWithCachePolicy};
|
pub use cached_client::{CachedClient, CachedClientError, DataWithCachePolicy};
|
||||||
pub use error::Error;
|
pub use error::Error;
|
||||||
pub use flat_index::{FlatDistributions, FlatIndex, FlatIndexClient};
|
pub use flat_index::{FlatDistributions, FlatIndex, FlatIndexClient, FlatIndexError};
|
||||||
pub use registry_client::{
|
pub use registry_client::{
|
||||||
read_metadata_async, RegistryClient, RegistryClientBuilder, SimpleMetadata, VersionFiles,
|
read_metadata_async, RegistryClient, RegistryClientBuilder, SimpleMetadata, VersionFiles,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue