From e85cd26a7a5e04d81241bddfe44b1127a62e951e Mon Sep 17 00:00:00 2001 From: Ahmed Ilyas Date: Fri, 27 Sep 2024 14:42:34 +0200 Subject: [PATCH] Indicate which package failed in the error message for `uv build --all` (#7736) ## Summary Small follow up to https://github.com/astral-sh/uv/pull/7724 ## Test Plan `cargo test` --------- Co-authored-by: Charlie Marsh --- crates/uv/src/commands/build.rs | 120 ++++++++++++++++++-------------- crates/uv/tests/build.rs | 2 +- 2 files changed, 68 insertions(+), 54 deletions(-) diff --git a/crates/uv/src/commands/build.rs b/crates/uv/src/commands/build.rs index efc383801..6bb42f3b2 100644 --- a/crates/uv/src/commands/build.rs +++ b/crates/uv/src/commands/build.rs @@ -58,7 +58,7 @@ pub(crate) async fn build( cache: &Cache, printer: Printer, ) -> Result { - let results = build_impl( + let build_result = build_impl( project_dir, src.as_deref(), package.as_ref(), @@ -82,53 +82,19 @@ pub(crate) async fn build( ) .await?; - for result in &results { - match result { - Ok(assets) => match assets { - BuiltDistributions::Wheel(wheel) => { - writeln!( - printer.stderr(), - "Successfully built {}", - wheel.user_display().bold().cyan() - )?; - } - BuiltDistributions::Sdist(sdist) => { - writeln!( - printer.stderr(), - "Successfully built {}", - sdist.user_display().bold().cyan() - )?; - } - BuiltDistributions::Both(sdist, wheel) => { - writeln!( - printer.stderr(), - "Successfully built {} and {}", - sdist.user_display().bold().cyan(), - wheel.user_display().bold().cyan() - )?; - } - }, - Err(err) => { - let mut causes = err.chain(); - writeln!( - printer.stderr(), - "{}: {}", - "error".red().bold(), - causes.next().unwrap() - )?; - - for err in causes { - writeln!(printer.stderr(), " {}: {}", "Caused by".red().bold(), err)?; - } - } - } + match build_result { + BuildResult::Failure => Ok(ExitStatus::Error), + BuildResult::Success => Ok(ExitStatus::Success), } +} - if results.iter().any(std::result::Result::is_err) { - Ok(ExitStatus::Error) - } else { - Ok(ExitStatus::Success) - } +/// Represents the overall result of a build process. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +enum BuildResult { + /// Indicates that at least one of the builds failed. + Failure, + /// Indicates that all builds succeeded. + Success, } #[allow(clippy::fn_params_excessive_bools)] @@ -153,7 +119,7 @@ async fn build_impl( native_tls: bool, cache: &Cache, printer: Printer, -) -> Result>> { +) -> Result { // Extract the resolver settings. let ResolverSettingsRef { index_locations, @@ -261,9 +227,9 @@ async fn build_impl( vec![AnnotatedSource::from(src)] }; - let builds = packages.into_iter().map(|src| { - build_package( - src, + let results: Vec<_> = futures::future::join_all(packages.into_iter().map(|source| { + let future = build_package( + source.clone(), output_dir, python_request, no_config, @@ -293,10 +259,58 @@ async fn build_impl( dependency_metadata, link_mode, config_setting, - ) - }); + ); + async { + let result = future.await; + (source, result) + } + })) + .await; - Ok(futures::future::join_all(builds).await) + for (source, result) in &results { + match result { + Ok(assets) => match assets { + BuiltDistributions::Wheel(wheel) => { + writeln!( + printer.stderr(), + "Successfully built {}", + wheel.user_display().bold().cyan() + )?; + } + BuiltDistributions::Sdist(sdist) => { + writeln!( + printer.stderr(), + "Successfully built {}", + sdist.user_display().bold().cyan() + )?; + } + BuiltDistributions::Both(sdist, wheel) => { + writeln!( + printer.stderr(), + "Successfully built {} and {}", + sdist.user_display().bold().cyan(), + wheel.user_display().bold().cyan() + )?; + } + }, + Err(err) => { + let mut causes = err.chain(); + + let message = format!("{}: {}", "error".red().bold(), causes.next().unwrap()); + writeln!(printer.stderr(), "{}", source.annotate(&message))?; + + for err in causes { + writeln!(printer.stderr(), " {}: {}", "Caused by".red().bold(), err)?; + } + } + } + } + + if results.iter().any(|(_, result)| result.is_err()) { + Ok(BuildResult::Failure) + } else { + Ok(BuildResult::Success) + } } #[allow(clippy::fn_params_excessive_bools)] diff --git a/crates/uv/tests/build.rs b/crates/uv/tests/build.rs index 090f9f31d..e7da73844 100644 --- a/crates/uv/tests/build.rs +++ b/crates/uv/tests/build.rs @@ -1328,7 +1328,7 @@ fn build_all_with_failure() -> Result<()> { [PKG] Building wheel from source distribution... [PKG] Building wheel from source distribution... Successfully built packages/member_a/dist/member_a-0.1.0.tar.gz and packages/member_a/dist/member_a-0.1.0-py3-none-any.whl - error: Build backend failed to determine extra requires with `build_sdist()` with exit status: 1 + [PKG] error: Build backend failed to determine extra requires with `build_sdist()` with exit status: 1 Successfully built dist/project-0.1.0.tar.gz and dist/project-0.1.0-py3-none-any.whl "###);