Include exit code for build failures (#2108)

`uv pip install mysqlclient==2.1.1` on python 3.12 on windows, where the
are no binary wheels:

![grafik](31f6294a-d845-4c85-b663-82a82ae925a6)

Part of #2052.
This commit is contained in:
konsti 2024-03-06 02:05:50 +01:00 committed by GitHub
parent 65518c9c58
commit df06069922
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 22 additions and 8 deletions

View file

@ -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};
@ -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]
@ -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 {
@ -169,6 +172,7 @@ impl Error {
Self::BuildBackend {
message,
exit_code: output.status,
stdout,
stderr,
}
@ -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
@ -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:

View file

@ -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(),
});
@ -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(),
}

View file

@ -1,6 +1,7 @@
use std::ffi::OsString;
use std::io;
use std::path::PathBuf;
use std::process::ExitStatus;
use thiserror::Error;
@ -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,
},

View file

@ -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(),
});
@ -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(),
})?;