Skip to content

Commit

Permalink
Allow downloading wheels for metadata with --no-binary
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Aug 1, 2024
1 parent 3c7526b commit d53bb2a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
1 change: 1 addition & 0 deletions crates/uv-dispatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ impl<'a> BuildContext for BuildDispatch<'a> {
self.cache,
tags,
&HashStrategy::None,
self.build_options,
DistributionDatabase::new(
self.client,
self,
Expand Down
8 changes: 0 additions & 8 deletions crates/uv-distribution/src/distribution_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,6 @@ impl<'a, Context: BuildContext> DistributionDatabase<'a, Context> {
dist: &BuiltDist,
hashes: HashPolicy<'_>,
) -> Result<LocalWheel, Error> {
if self
.build_context
.build_options()
.no_binary_package(dist.name())
{
return Err(Error::NoBinary);
}

match dist {
BuiltDist::Registry(wheels) => {
let wheel = wheels.best_wheel();
Expand Down
2 changes: 0 additions & 2 deletions crates/uv-distribution/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ use uv_normalize::PackageName;
pub enum Error {
#[error("Building source distributions is disabled")]
NoBuild,
#[error("Using pre-built wheels is disabled")]
NoBinary,

// Network error
#[error("Failed to parse URL: {0}")]
Expand Down
38 changes: 36 additions & 2 deletions crates/uv-installer/src/preparer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,24 @@ use std::sync::Arc;
use futures::{stream::FuturesUnordered, FutureExt, Stream, TryFutureExt, TryStreamExt};
use pep508_rs::PackageName;
use tokio::task::JoinError;
use tracing::instrument;
use tracing::{debug, instrument};
use url::Url;

use distribution_types::{BuildableSource, CachedDist, Dist, Hashed, Identifier, RemoteSource};
use distribution_types::{
BuildableSource, CachedDist, Dist, Hashed, Identifier, Name, RemoteSource,
};
use platform_tags::Tags;
use uv_cache::Cache;
use uv_configuration::BuildOptions;
use uv_distribution::{DistributionDatabase, LocalWheel};
use uv_types::{BuildContext, HashStrategy, InFlight};

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("Building source distributions is disabled, but attempted to build `{0}`")]
NoBuild(PackageName),
#[error("Using pre-built wheels is disabled, but attempted to use `{0}`")]
NoBinary(PackageName),
#[error("Failed to unzip wheel: {0}")]
Unzip(Dist, #[source] uv_extract::Error),
#[error("Failed to fetch wheel: {0}")]
Expand All @@ -37,6 +44,7 @@ pub struct Preparer<'a, Context: BuildContext> {
tags: &'a Tags,
cache: &'a Cache,
hashes: &'a HashStrategy,
build_options: &'a BuildOptions,
database: DistributionDatabase<'a, Context>,
reporter: Option<Arc<dyn Reporter>>,
}
Expand All @@ -46,12 +54,14 @@ impl<'a, Context: BuildContext> Preparer<'a, Context> {
cache: &'a Cache,
tags: &'a Tags,
hashes: &'a HashStrategy,
build_options: &'a BuildOptions,
database: DistributionDatabase<'a, Context>,
) -> Self {
Self {
tags,
cache,
hashes,
build_options,
database,
reporter: None,
}
Expand All @@ -65,6 +75,7 @@ impl<'a, Context: BuildContext> Preparer<'a, Context> {
tags: self.tags,
cache: self.cache,
hashes: self.hashes,
build_options: self.build_options,
database: self.database.with_reporter(Facade::from(reporter.clone())),
reporter: Some(reporter.clone()),
}
Expand Down Expand Up @@ -111,9 +122,32 @@ impl<'a, Context: BuildContext> Preparer<'a, Context> {
Ok(wheels)
}

/// Validate that the [`Dist`] is compatible with the [`BuildOptions`] policy.
fn validate(&self, dist: &Dist) -> Result<(), Error> {
match dist {
Dist::Built(ref dist) => {
if self.build_options.no_binary_package(dist.name()) {
return Err(Error::NoBinary(dist.name().clone()));
}
}
Dist::Source(ref dist) => {
if self.build_options.no_build_package(dist.name()) {
if dist.is_editable() {
debug!("Allowing build for editable source distribution: {dist}");
} else {
return Err(Error::NoBuild(dist.name().clone()));
}
}
}
}
Ok(())
}

/// Download, build, and unzip a single wheel.
#[instrument(skip_all, fields(name = % dist, size = ? dist.size(), url = dist.file().map(| file | file.url.to_string()).unwrap_or_default()))]
pub async fn get_wheel(&self, dist: Dist, in_flight: &InFlight) -> Result<CachedDist, Error> {
self.validate(&dist)?;

let id = dist.distribution_id();
if in_flight.downloads.register(id.clone()) {
let policy = self.hashes.get(&dist);
Expand Down
1 change: 1 addition & 0 deletions crates/uv/src/commands/pip/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ pub(crate) async fn install(
cache,
tags,
hasher,
build_options,
DistributionDatabase::new(client, build_dispatch, concurrency.downloads, preview),
)
.with_reporter(PrepareReporter::from(printer).with_length(remote.len() as u64));
Expand Down

0 comments on commit d53bb2a

Please sign in to comment.