Skip to content

Commit

Permalink
Rename Downloader for clarity
Browse files Browse the repository at this point in the history
Follow-up to #4394 with internal refactor
  • Loading branch information
zanieb committed Jun 18, 2024
1 parent 8302386 commit 389a3be
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
10 changes: 5 additions & 5 deletions crates/uv-dispatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use uv_configuration::{BuildKind, BuildOptions, ConfigSettings, Reinstall, Setup
use uv_configuration::{Concurrency, PreviewMode};
use uv_distribution::DistributionDatabase;
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_toolchain::{Interpreter, PythonEnvironment};
use uv_types::{BuildContext, BuildIsolation, EmptyInstalledPackages, HashStrategy, InFlight};
Expand Down Expand Up @@ -240,7 +240,7 @@ impl<'a> BuildContext for BuildDispatch<'a> {
vec![]
} else {
// TODO(konstin): Check that there is no endless recursion.
let downloader = Downloader::new(
let preparer = Preparer::new(
self.cache,
tags,
&HashStrategy::None,
Expand All @@ -258,10 +258,10 @@ impl<'a> BuildContext for BuildDispatch<'a> {
remote.iter().map(ToString::to_string).join(", ")
);

downloader
.download(remote, self.in_flight)
preparer
.prepare(remote, self.in_flight)
.await
.context("Failed to download and build distributions")?
.context("Failed to prepare distributions")?
};

// Remove any unnecessary packages.
Expand Down
4 changes: 2 additions & 2 deletions crates/uv-installer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
pub use compile::{compile_tree, CompileError};
pub use downloader::{Downloader, Reporter as DownloadReporter};
pub use installer::{Installer, Reporter as InstallReporter};
pub use plan::{Plan, Planner};
pub use preparer::{Preparer, Reporter as DownloadReporter};
pub use site_packages::{SatisfiesResult, SitePackages, SitePackagesDiagnostic};
pub use uninstall::{uninstall, UninstallError};

mod compile;
mod downloader;
mod preparer;

mod installer;
mod plan;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ pub enum Error {
Thread(String),
}

/// Download, build, and unzip a set of distributions.
pub struct Downloader<'a, Context: BuildContext> {
/// Prepare distributions for installation.
///
/// Downloads, builds, and unzips a set of distributions.
pub struct Preparer<'a, Context: BuildContext> {
tags: &'a Tags,
cache: &'a Cache,
hashes: &'a HashStrategy,
database: DistributionDatabase<'a, Context>,
reporter: Option<Arc<dyn Reporter>>,
}

impl<'a, Context: BuildContext> Downloader<'a, Context> {
impl<'a, Context: BuildContext> Preparer<'a, Context> {
pub fn new(
cache: &'a Cache,
tags: &'a Tags,
Expand All @@ -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]
pub fn with_reporter(self, reporter: impl Reporter + 'static) -> Self {
let reporter: Arc<dyn Reporter> = Arc::new(reporter);
Expand All @@ -69,7 +71,7 @@ impl<'a, Context: BuildContext> Downloader<'a, Context> {
}

/// Fetch, build, and unzip the distributions in parallel.
pub fn download_stream<'stream>(
pub fn prepare_stream<'stream>(
&'stream self,
distributions: Vec<Dist>,
in_flight: &'stream InFlight,
Expand All @@ -86,9 +88,9 @@ impl<'a, Context: BuildContext> Downloader<'a, Context> {
.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()))]
pub async fn download(
pub async fn prepare(
&self,
mut distributions: Vec<Dist>,
in_flight: &InFlight,
Expand All @@ -98,7 +100,7 @@ impl<'a, Context: BuildContext> Downloader<'a, Context> {
.sort_unstable_by_key(|distribution| Reverse(distribution.size().unwrap_or(u64::MAX)));

let wheels = self
.download_stream(distributions, in_flight)
.prepare_stream(distributions, in_flight)
.try_collect()
.await?;

Expand Down
10 changes: 5 additions & 5 deletions crates/uv/src/commands/pip/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use uv_configuration::{
use uv_dispatch::BuildDispatch;
use uv_distribution::DistributionDatabase;
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_requirements::{
LookaheadResolver, NamedRequirementsResolver, RequirementsSource, RequirementsSpecification,
Expand Down Expand Up @@ -375,18 +375,18 @@ pub(crate) async fn install(
} else {
let start = std::time::Instant::now();

let downloader = Downloader::new(
let preparer = Preparer::new(
cache,
tags,
hasher,
DistributionDatabase::new(client, build_dispatch, concurrency.downloads, preview),
)
.with_reporter(DownloadReporter::from(printer).with_length(remote.len() as u64));

let wheels = downloader
.download(remote.clone(), in_flight)
let wheels = preparer
.prepare(remote.clone(), in_flight)
.await
.context("Failed to download distributions")?;
.context("Failed to prepare distributions")?;

let s = if wheels.len() == 1 { "" } else { "s" };
writeln!(
Expand Down

0 comments on commit 389a3be

Please sign in to comment.