Rename Downloader for clarity (#4395)

Follow-up to https://github.com/astral-sh/uv/pull/4394 with internal
refactor
This commit is contained in:
Zanie Blue 2024-06-18 17:00:10 -04:00 committed by GitHub
parent b22ee82f0d
commit f219f88553
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 43 additions and 41 deletions

View file

@ -20,7 +20,7 @@ use uv_configuration::{BuildKind, BuildOptions, ConfigSettings, Reinstall, Setup
use uv_configuration::{Concurrency, PreviewMode}; use uv_configuration::{Concurrency, PreviewMode};
use uv_distribution::DistributionDatabase; use uv_distribution::DistributionDatabase;
use uv_git::GitResolver; use uv_git::GitResolver;
use uv_installer::{Downloader, Installer, Plan, Planner, SitePackages}; use uv_installer::{Installer, Plan, Planner, Preparer, SitePackages};
use uv_resolver::{FlatIndex, InMemoryIndex, Manifest, Options, PythonRequirement, Resolver}; use uv_resolver::{FlatIndex, InMemoryIndex, Manifest, Options, PythonRequirement, Resolver};
use uv_toolchain::{Interpreter, PythonEnvironment}; use uv_toolchain::{Interpreter, PythonEnvironment};
use uv_types::{BuildContext, BuildIsolation, EmptyInstalledPackages, HashStrategy, InFlight}; use uv_types::{BuildContext, BuildIsolation, EmptyInstalledPackages, HashStrategy, InFlight};
@ -240,7 +240,7 @@ impl<'a> BuildContext for BuildDispatch<'a> {
vec![] vec![]
} else { } else {
// TODO(konstin): Check that there is no endless recursion. // TODO(konstin): Check that there is no endless recursion.
let downloader = Downloader::new( let preparer = Preparer::new(
self.cache, self.cache,
tags, tags,
&HashStrategy::None, &HashStrategy::None,
@ -258,10 +258,10 @@ impl<'a> BuildContext for BuildDispatch<'a> {
remote.iter().map(ToString::to_string).join(", ") remote.iter().map(ToString::to_string).join(", ")
); );
downloader preparer
.download(remote, self.in_flight) .prepare(remote, self.in_flight)
.await .await
.context("Failed to download and build distributions")? .context("Failed to prepare distributions")?
}; };
// Remove any unnecessary packages. // Remove any unnecessary packages.

View file

@ -1,12 +1,12 @@
pub use compile::{compile_tree, CompileError}; pub use compile::{compile_tree, CompileError};
pub use downloader::{Downloader, Reporter as DownloadReporter};
pub use installer::{Installer, Reporter as InstallReporter}; pub use installer::{Installer, Reporter as InstallReporter};
pub use plan::{Plan, Planner}; pub use plan::{Plan, Planner};
pub use preparer::{Preparer, Reporter as PrepareReporter};
pub use site_packages::{SatisfiesResult, SitePackages, SitePackagesDiagnostic}; pub use site_packages::{SatisfiesResult, SitePackages, SitePackagesDiagnostic};
pub use uninstall::{uninstall, UninstallError}; pub use uninstall::{uninstall, UninstallError};
mod compile; mod compile;
mod downloader; mod preparer;
mod installer; mod installer;
mod plan; mod plan;

View file

@ -30,8 +30,10 @@ pub enum Error {
Thread(String), Thread(String),
} }
/// Download, build, and unzip a set of distributions. /// Prepare distributions for installation.
pub struct Downloader<'a, Context: BuildContext> { ///
/// Downloads, builds, and unzips a set of distributions.
pub struct Preparer<'a, Context: BuildContext> {
tags: &'a Tags, tags: &'a Tags,
cache: &'a Cache, cache: &'a Cache,
hashes: &'a HashStrategy, hashes: &'a HashStrategy,
@ -39,7 +41,7 @@ pub struct Downloader<'a, Context: BuildContext> {
reporter: Option<Arc<dyn Reporter>>, reporter: Option<Arc<dyn Reporter>>,
} }
impl<'a, Context: BuildContext> Downloader<'a, Context> { impl<'a, Context: BuildContext> Preparer<'a, Context> {
pub fn new( pub fn new(
cache: &'a Cache, cache: &'a Cache,
tags: &'a Tags, tags: &'a Tags,
@ -55,7 +57,7 @@ impl<'a, Context: BuildContext> Downloader<'a, Context> {
} }
} }
/// Set the [`Reporter`] to use for this downloader. /// Set the [`Reporter`] to use for operations.
#[must_use] #[must_use]
pub fn with_reporter(self, reporter: impl Reporter + 'static) -> Self { pub fn with_reporter(self, reporter: impl Reporter + 'static) -> Self {
let reporter: Arc<dyn Reporter> = Arc::new(reporter); let reporter: Arc<dyn Reporter> = Arc::new(reporter);
@ -69,7 +71,7 @@ impl<'a, Context: BuildContext> Downloader<'a, Context> {
} }
/// Fetch, build, and unzip the distributions in parallel. /// Fetch, build, and unzip the distributions in parallel.
pub fn download_stream<'stream>( pub fn prepare_stream<'stream>(
&'stream self, &'stream self,
distributions: Vec<Dist>, distributions: Vec<Dist>,
in_flight: &'stream InFlight, in_flight: &'stream InFlight,
@ -86,9 +88,9 @@ impl<'a, Context: BuildContext> Downloader<'a, Context> {
.collect::<FuturesUnordered<_>>() .collect::<FuturesUnordered<_>>()
} }
/// Download, build, and unzip a set of downloaded wheels. /// Download, build, and unzip a set of distributions.
#[instrument(skip_all, fields(total = distributions.len()))] #[instrument(skip_all, fields(total = distributions.len()))]
pub async fn download( pub async fn prepare(
&self, &self,
mut distributions: Vec<Dist>, mut distributions: Vec<Dist>,
in_flight: &InFlight, in_flight: &InFlight,
@ -98,7 +100,7 @@ impl<'a, Context: BuildContext> Downloader<'a, Context> {
.sort_unstable_by_key(|distribution| Reverse(distribution.size().unwrap_or(u64::MAX))); .sort_unstable_by_key(|distribution| Reverse(distribution.size().unwrap_or(u64::MAX)));
let wheels = self let wheels = self
.download_stream(distributions, in_flight) .prepare_stream(distributions, in_flight)
.try_collect() .try_collect()
.await?; .await?;

View file

@ -27,7 +27,7 @@ use uv_configuration::{
use uv_dispatch::BuildDispatch; use uv_dispatch::BuildDispatch;
use uv_distribution::DistributionDatabase; use uv_distribution::DistributionDatabase;
use uv_fs::Simplified; use uv_fs::Simplified;
use uv_installer::{Downloader, Plan, Planner, SitePackages}; use uv_installer::{Plan, Planner, Preparer, SitePackages};
use uv_normalize::{GroupName, PackageName}; use uv_normalize::{GroupName, PackageName};
use uv_requirements::{ use uv_requirements::{
LookaheadResolver, NamedRequirementsResolver, RequirementsSource, RequirementsSpecification, LookaheadResolver, NamedRequirementsResolver, RequirementsSource, RequirementsSpecification,
@ -41,7 +41,7 @@ use uv_toolchain::{Interpreter, PythonEnvironment};
use uv_types::{HashStrategy, InFlight, InstalledPackagesProvider}; use uv_types::{HashStrategy, InFlight, InstalledPackagesProvider};
use uv_warnings::warn_user; use uv_warnings::warn_user;
use crate::commands::reporters::{DownloadReporter, InstallReporter, ResolverReporter}; use crate::commands::reporters::{InstallReporter, PrepareReporter, ResolverReporter};
use crate::commands::{compile_bytecode, elapsed, ChangeEvent, ChangeEventKind, DryRunEvent}; use crate::commands::{compile_bytecode, elapsed, ChangeEvent, ChangeEventKind, DryRunEvent};
use crate::printer::Printer; use crate::printer::Printer;
@ -375,18 +375,18 @@ pub(crate) async fn install(
} else { } else {
let start = std::time::Instant::now(); let start = std::time::Instant::now();
let downloader = Downloader::new( let preparer = Preparer::new(
cache, cache,
tags, tags,
hasher, hasher,
DistributionDatabase::new(client, build_dispatch, concurrency.downloads, preview), DistributionDatabase::new(client, build_dispatch, concurrency.downloads, preview),
) )
.with_reporter(DownloadReporter::from(printer).with_length(remote.len() as u64)); .with_reporter(PrepareReporter::from(printer).with_length(remote.len() as u64));
let wheels = downloader let wheels = preparer
.download(remote.clone(), in_flight) .prepare(remote.clone(), in_flight)
.await .await
.context("Failed to download distributions")?; .context("Failed to prepare distributions")?;
let s = if wheels.len() == 1 { "" } else { "s" }; let s = if wheels.len() == 1 { "" } else { "s" };
writeln!( writeln!(

View file

@ -229,11 +229,11 @@ impl ProgressReporter {
} }
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct DownloadReporter { pub(crate) struct PrepareReporter {
reporter: ProgressReporter, reporter: ProgressReporter,
} }
impl From<Printer> for DownloadReporter { impl From<Printer> for PrepareReporter {
fn from(printer: Printer) -> Self { fn from(printer: Printer) -> Self {
let multi_progress = MultiProgress::with_draw_target(printer.target()); let multi_progress = MultiProgress::with_draw_target(printer.target());
let root = multi_progress.add(ProgressBar::with_draw_target(None, printer.target())); let root = multi_progress.add(ProgressBar::with_draw_target(None, printer.target()));
@ -250,7 +250,7 @@ impl From<Printer> for DownloadReporter {
} }
} }
impl DownloadReporter { impl PrepareReporter {
#[must_use] #[must_use]
pub(crate) fn with_length(self, length: u64) -> Self { pub(crate) fn with_length(self, length: u64) -> Self {
self.reporter.root.set_length(length); self.reporter.root.set_length(length);
@ -258,7 +258,7 @@ impl DownloadReporter {
} }
} }
impl uv_installer::DownloadReporter for DownloadReporter { impl uv_installer::PrepareReporter for PrepareReporter {
fn on_progress(&self, _dist: &CachedDist) { fn on_progress(&self, _dist: &CachedDist) {
self.reporter.root.inc(1); self.reporter.root.inc(1);
} }

View file

@ -3519,7 +3519,7 @@ fn require_hashes_wheel_no_binary() -> Result<()> {
----- stderr ----- ----- stderr -----
Resolved 1 package in [TIME] Resolved 1 package in [TIME]
error: Failed to download distributions error: Failed to prepare distributions
Caused by: Failed to fetch wheel: anyio==4.0.0 Caused by: Failed to fetch wheel: anyio==4.0.0
Caused by: Hash mismatch for `anyio==4.0.0` Caused by: Hash mismatch for `anyio==4.0.0`
@ -3612,7 +3612,7 @@ fn require_hashes_source_only_binary() -> Result<()> {
----- stderr ----- ----- stderr -----
Resolved 1 package in [TIME] Resolved 1 package in [TIME]
error: Failed to download distributions error: Failed to prepare distributions
Caused by: Failed to fetch wheel: anyio==4.0.0 Caused by: Failed to fetch wheel: anyio==4.0.0
Caused by: Hash mismatch for `anyio==4.0.0` Caused by: Hash mismatch for `anyio==4.0.0`
@ -3645,7 +3645,7 @@ fn require_hashes_wrong_digest() -> Result<()> {
----- stderr ----- ----- stderr -----
Resolved 1 package in [TIME] Resolved 1 package in [TIME]
error: Failed to download distributions error: Failed to prepare distributions
Caused by: Failed to fetch wheel: anyio==4.0.0 Caused by: Failed to fetch wheel: anyio==4.0.0
Caused by: Hash mismatch for `anyio==4.0.0` Caused by: Hash mismatch for `anyio==4.0.0`
@ -3678,7 +3678,7 @@ fn require_hashes_wrong_algorithm() -> Result<()> {
----- stderr ----- ----- stderr -----
Resolved 1 package in [TIME] Resolved 1 package in [TIME]
error: Failed to download distributions error: Failed to prepare distributions
Caused by: Failed to fetch wheel: anyio==4.0.0 Caused by: Failed to fetch wheel: anyio==4.0.0
Caused by: Hash mismatch for `anyio==4.0.0` Caused by: Hash mismatch for `anyio==4.0.0`
@ -3851,7 +3851,7 @@ fn require_hashes_wheel_url() -> Result<()> {
----- stderr ----- ----- stderr -----
Resolved 1 package in [TIME] Resolved 1 package in [TIME]
error: Failed to download distributions error: Failed to prepare distributions
Caused by: Failed to fetch wheel: anyio @ https://files.pythonhosted.org/packages/36/55/ad4de788d84a630656ece71059665e01ca793c04294c463fd84132f40fe6/anyio-4.0.0-py3-none-any.whl Caused by: Failed to fetch wheel: anyio @ https://files.pythonhosted.org/packages/36/55/ad4de788d84a630656ece71059665e01ca793c04294c463fd84132f40fe6/anyio-4.0.0-py3-none-any.whl
Caused by: Hash mismatch for `anyio @ https://files.pythonhosted.org/packages/36/55/ad4de788d84a630656ece71059665e01ca793c04294c463fd84132f40fe6/anyio-4.0.0-py3-none-any.whl` Caused by: Hash mismatch for `anyio @ https://files.pythonhosted.org/packages/36/55/ad4de788d84a630656ece71059665e01ca793c04294c463fd84132f40fe6/anyio-4.0.0-py3-none-any.whl`
@ -3906,7 +3906,7 @@ fn require_hashes_wheel_url_mismatch() -> Result<()> {
----- stderr ----- ----- stderr -----
Resolved 1 package in [TIME] Resolved 1 package in [TIME]
error: Failed to download distributions error: Failed to prepare distributions
Caused by: Failed to fetch wheel: anyio @ https://files.pythonhosted.org/packages/36/55/ad4de788d84a630656ece71059665e01ca793c04294c463fd84132f40fe6/anyio-4.0.0-py3-none-any.whl Caused by: Failed to fetch wheel: anyio @ https://files.pythonhosted.org/packages/36/55/ad4de788d84a630656ece71059665e01ca793c04294c463fd84132f40fe6/anyio-4.0.0-py3-none-any.whl
Caused by: Hash mismatch for `anyio @ https://files.pythonhosted.org/packages/36/55/ad4de788d84a630656ece71059665e01ca793c04294c463fd84132f40fe6/anyio-4.0.0-py3-none-any.whl` Caused by: Hash mismatch for `anyio @ https://files.pythonhosted.org/packages/36/55/ad4de788d84a630656ece71059665e01ca793c04294c463fd84132f40fe6/anyio-4.0.0-py3-none-any.whl`
@ -4014,7 +4014,7 @@ fn require_hashes_re_download() -> Result<()> {
----- stderr ----- ----- stderr -----
Resolved 1 package in [TIME] Resolved 1 package in [TIME]
error: Failed to download distributions error: Failed to prepare distributions
Caused by: Failed to fetch wheel: anyio==4.0.0 Caused by: Failed to fetch wheel: anyio==4.0.0
Caused by: Hash mismatch for `anyio==4.0.0` Caused by: Hash mismatch for `anyio==4.0.0`
@ -4106,7 +4106,7 @@ fn require_hashes_wheel_path_mismatch() -> Result<()> {
----- stderr ----- ----- stderr -----
Resolved 1 package in [TIME] Resolved 1 package in [TIME]
error: Failed to download distributions error: Failed to prepare distributions
Caused by: Failed to fetch wheel: tqdm @ file://[WORKSPACE]/scripts/links/tqdm-1000.0.0-py3-none-any.whl Caused by: Failed to fetch wheel: tqdm @ file://[WORKSPACE]/scripts/links/tqdm-1000.0.0-py3-none-any.whl
Caused by: Hash mismatch for `tqdm @ file://[WORKSPACE]/scripts/links/tqdm-1000.0.0-py3-none-any.whl` Caused by: Hash mismatch for `tqdm @ file://[WORKSPACE]/scripts/links/tqdm-1000.0.0-py3-none-any.whl`
@ -4385,7 +4385,7 @@ fn require_hashes_repeated_hash() -> Result<()> {
----- stderr ----- ----- stderr -----
Resolved 1 package in [TIME] Resolved 1 package in [TIME]
error: Failed to download distributions error: Failed to prepare distributions
Caused by: Failed to fetch wheel: anyio @ https://files.pythonhosted.org/packages/36/55/ad4de788d84a630656ece71059665e01ca793c04294c463fd84132f40fe6/anyio-4.0.0-py3-none-any.whl Caused by: Failed to fetch wheel: anyio @ https://files.pythonhosted.org/packages/36/55/ad4de788d84a630656ece71059665e01ca793c04294c463fd84132f40fe6/anyio-4.0.0-py3-none-any.whl
Caused by: Hash mismatch for `anyio @ https://files.pythonhosted.org/packages/36/55/ad4de788d84a630656ece71059665e01ca793c04294c463fd84132f40fe6/anyio-4.0.0-py3-none-any.whl` Caused by: Hash mismatch for `anyio @ https://files.pythonhosted.org/packages/36/55/ad4de788d84a630656ece71059665e01ca793c04294c463fd84132f40fe6/anyio-4.0.0-py3-none-any.whl`
@ -4517,7 +4517,7 @@ fn require_hashes_find_links_no_hash() -> Result<()> {
----- stderr ----- ----- stderr -----
Resolved 1 package in [TIME] Resolved 1 package in [TIME]
error: Failed to download distributions error: Failed to prepare distributions
Caused by: Failed to fetch wheel: example-a-961b4c22==1.0.0 Caused by: Failed to fetch wheel: example-a-961b4c22==1.0.0
Caused by: Hash mismatch for `example-a-961b4c22==1.0.0` Caused by: Hash mismatch for `example-a-961b4c22==1.0.0`
@ -4547,7 +4547,7 @@ fn require_hashes_find_links_no_hash() -> Result<()> {
----- stderr ----- ----- stderr -----
Resolved 1 package in [TIME] Resolved 1 package in [TIME]
error: Failed to download distributions error: Failed to prepare distributions
Caused by: Failed to fetch wheel: example-a-961b4c22==1.0.0 Caused by: Failed to fetch wheel: example-a-961b4c22==1.0.0
Caused by: Hash mismatch for `example-a-961b4c22==1.0.0` Caused by: Hash mismatch for `example-a-961b4c22==1.0.0`
@ -4639,7 +4639,7 @@ fn require_hashes_find_links_invalid_hash() -> Result<()> {
----- stderr ----- ----- stderr -----
Resolved 1 package in [TIME] Resolved 1 package in [TIME]
error: Failed to download distributions error: Failed to prepare distributions
Caused by: Failed to fetch wheel: example-a-961b4c22==1.0.0 Caused by: Failed to fetch wheel: example-a-961b4c22==1.0.0
Caused by: Hash mismatch for `example-a-961b4c22==1.0.0` Caused by: Hash mismatch for `example-a-961b4c22==1.0.0`
@ -4668,7 +4668,7 @@ fn require_hashes_find_links_invalid_hash() -> Result<()> {
----- stderr ----- ----- stderr -----
Resolved 1 package in [TIME] Resolved 1 package in [TIME]
error: Failed to download distributions error: Failed to prepare distributions
Caused by: Failed to fetch wheel: example-a-961b4c22==1.0.0 Caused by: Failed to fetch wheel: example-a-961b4c22==1.0.0
Caused by: Hash mismatch for `example-a-961b4c22==1.0.0` Caused by: Hash mismatch for `example-a-961b4c22==1.0.0`
@ -4840,7 +4840,7 @@ fn require_hashes_registry_invalid_hash() -> Result<()> {
----- stderr ----- ----- stderr -----
Resolved 1 package in [TIME] Resolved 1 package in [TIME]
error: Failed to download distributions error: Failed to prepare distributions
Caused by: Failed to fetch wheel: example-a-961b4c22==1.0.0 Caused by: Failed to fetch wheel: example-a-961b4c22==1.0.0
Caused by: Hash mismatch for `example-a-961b4c22==1.0.0` Caused by: Hash mismatch for `example-a-961b4c22==1.0.0`
@ -4869,7 +4869,7 @@ fn require_hashes_registry_invalid_hash() -> Result<()> {
----- stderr ----- ----- stderr -----
Resolved 1 package in [TIME] Resolved 1 package in [TIME]
error: Failed to download distributions error: Failed to prepare distributions
Caused by: Failed to fetch wheel: example-a-961b4c22==1.0.0 Caused by: Failed to fetch wheel: example-a-961b4c22==1.0.0
Caused by: Hash mismatch for `example-a-961b4c22==1.0.0` Caused by: Hash mismatch for `example-a-961b4c22==1.0.0`