Skip to content

Commit

Permalink
Include exit code for build failures (#2108)
Browse files Browse the repository at this point in the history
`uv pip install mysqlclient==2.1.1` on python 3.12 on windows, where the
are no binary wheels:

![grafik](https://github.com/astral-sh/uv/assets/6826232/31f6294a-d845-4c85-b663-82a82ae925a6)

Part of #2052.
  • Loading branch information
konstin authored Mar 6, 2024
1 parent 65518c9 commit df06069
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
22 changes: 15 additions & 7 deletions crates/uv-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::fmt::{Display, Formatter};
use std::io;
use std::io::BufRead;
use std::path::{Path, PathBuf};
use std::process::Output;
use std::process::{ExitStatus, Output};
use std::str::FromStr;
use std::sync::Arc;
use std::{env, iter};
Expand Down Expand Up @@ -78,16 +78,18 @@ pub enum Error {
Virtualenv(#[from] uv_virtualenv::Error),
#[error("Failed to run {0}")]
CommandFailed(PathBuf, #[source] io::Error),
#[error("{message}:\n--- stdout:\n{stdout}\n--- stderr:\n{stderr}\n---")]
#[error("{message} with {exit_code}\n--- stdout:\n{stdout}\n--- stderr:\n{stderr}\n---")]
BuildBackend {
message: String,
exit_code: ExitStatus,
stdout: String,
stderr: String,
},
/// Nudge the user towards installing the missing dev library
#[error("{message}:\n--- stdout:\n{stdout}\n--- stderr:\n{stderr}\n---")]
#[error("{message} with {exit_code}\n--- stdout:\n{stdout}\n--- stderr:\n{stderr}\n---")]
MissingHeader {
message: String,
exit_code: ExitStatus,
stdout: String,
stderr: String,
#[source]
Expand Down Expand Up @@ -158,6 +160,7 @@ impl Error {
if let Some(missing_library) = missing_library {
return Self::MissingHeader {
message,
exit_code: output.status,
stdout,
stderr,
missing_header_cause: MissingHeaderCause {
Expand All @@ -169,6 +172,7 @@ impl Error {

Self::BuildBackend {
message,
exit_code: output.status,
stdout,
stderr,
}
Expand Down Expand Up @@ -968,8 +972,10 @@ mod test {
"pygraphviz-1.11",
);
assert!(matches!(err, Error::MissingHeader { .. }));
insta::assert_snapshot!(err, @r###"
Failed building wheel through setup.py:
// Unix uses exit status, Windows uses exit code.
let formatted = err.to_string().replace("exit status: ", "exit code: ");
insta::assert_snapshot!(formatted, @r###"
Failed building wheel through setup.py with exit code: 0
--- stdout:
running bdist_wheel
running build
Expand Down Expand Up @@ -1018,8 +1024,10 @@ mod test {
"pygraphviz-1.11",
);
assert!(matches!(err, Error::MissingHeader { .. }));
insta::assert_snapshot!(err, @r###"
Failed building wheel through setup.py:
// Unix uses exit status, Windows uses exit code.
let formatted = err.to_string().replace("exit status: ", "exit code: ");
insta::assert_snapshot!(formatted, @r###"
Failed building wheel through setup.py with exit code: 0
--- stdout:
--- stderr:
Expand Down
2 changes: 2 additions & 0 deletions crates/uv-interpreter/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ impl InterpreterInfo {
interpreter.display(),
output.status,
),
exit_code: output.status,
stdout: String::from_utf8_lossy(&output.stdout).trim().to_string(),
stderr: String::from_utf8_lossy(&output.stderr).trim().to_string(),
});
Expand All @@ -518,6 +519,7 @@ impl InterpreterInfo {
"Querying Python at `{}` did not return the expected data: {err}",
interpreter.display(),
),
exit_code: output.status,
stdout: String::from_utf8_lossy(&output.stdout).trim().to_string(),
stderr: String::from_utf8_lossy(&output.stderr).trim().to_string(),
}
Expand Down
4 changes: 3 additions & 1 deletion crates/uv-interpreter/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::ffi::OsString;
use std::io;
use std::path::PathBuf;
use std::process::ExitStatus;

use thiserror::Error;

Expand Down Expand Up @@ -54,9 +55,10 @@ pub enum Error {
"Could not find `python.exe` through `py --list-paths` or in 'PATH'. Is Python installed?"
)]
NoPythonInstalledWindows,
#[error("{message}:\n--- stdout:\n{stdout}\n--- stderr:\n{stderr}\n---")]
#[error("{message} with {exit_code}\n--- stdout:\n{stdout}\n--- stderr:\n{stderr}\n---")]
PythonSubcommandOutput {
message: String,
exit_code: ExitStatus,
stdout: String,
stderr: String,
},
Expand Down
2 changes: 2 additions & 0 deletions crates/uv-interpreter/src/python_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ mod windows {
"Running `py --list-paths` failed with status {}",
output.status
),
exit_code: output.status,
stdout: String::from_utf8_lossy(&output.stdout).trim().to_string(),
stderr: String::from_utf8_lossy(&output.stderr).trim().to_string(),
});
Expand All @@ -451,6 +452,7 @@ mod windows {
let stdout =
String::from_utf8(output.stdout).map_err(|err| Error::PythonSubcommandOutput {
message: format!("The stdout of `py --list-paths` isn't UTF-8 encoded: {err}"),
exit_code: output.status,
stdout: String::from_utf8_lossy(err.as_bytes()).trim().to_string(),
stderr: String::from_utf8_lossy(&output.stderr).trim().to_string(),
})?;
Expand Down

0 comments on commit df06069

Please sign in to comment.