Skip to content

Commit

Permalink
Indicate which package failed in the error message for `uv build --al…
Browse files Browse the repository at this point in the history
…l` (#7736)

## Summary

Small follow up to #7724

## Test Plan

`cargo test`

---------

Co-authored-by: Charlie Marsh <[email protected]>
  • Loading branch information
blueraft and charliermarsh authored Sep 27, 2024
1 parent 805f1bd commit e85cd26
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 54 deletions.
120 changes: 67 additions & 53 deletions crates/uv/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub(crate) async fn build(
cache: &Cache,
printer: Printer,
) -> Result<ExitStatus> {
let results = build_impl(
let build_result = build_impl(
project_dir,
src.as_deref(),
package.as_ref(),
Expand All @@ -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)]
Expand All @@ -153,7 +119,7 @@ async fn build_impl(
native_tls: bool,
cache: &Cache,
printer: Printer,
) -> Result<Vec<Result<BuiltDistributions>>> {
) -> Result<BuildResult> {
// Extract the resolver settings.
let ResolverSettingsRef {
index_locations,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
"###);

Expand Down

0 comments on commit e85cd26

Please sign in to comment.