mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-01 04:17:37 +00:00
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:

Part of #2052.
This commit is contained in:
parent
65518c9c58
commit
df06069922
4 changed files with 22 additions and 8 deletions
|
|
@ -7,7 +7,7 @@ use std::fmt::{Display, Formatter};
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::BufRead;
|
use std::io::BufRead;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::Output;
|
use std::process::{ExitStatus, Output};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::{env, iter};
|
use std::{env, iter};
|
||||||
|
|
@ -78,16 +78,18 @@ pub enum Error {
|
||||||
Virtualenv(#[from] uv_virtualenv::Error),
|
Virtualenv(#[from] uv_virtualenv::Error),
|
||||||
#[error("Failed to run {0}")]
|
#[error("Failed to run {0}")]
|
||||||
CommandFailed(PathBuf, #[source] io::Error),
|
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 {
|
BuildBackend {
|
||||||
message: String,
|
message: String,
|
||||||
|
exit_code: ExitStatus,
|
||||||
stdout: String,
|
stdout: String,
|
||||||
stderr: String,
|
stderr: String,
|
||||||
},
|
},
|
||||||
/// Nudge the user towards installing the missing dev library
|
/// 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 {
|
MissingHeader {
|
||||||
message: String,
|
message: String,
|
||||||
|
exit_code: ExitStatus,
|
||||||
stdout: String,
|
stdout: String,
|
||||||
stderr: String,
|
stderr: String,
|
||||||
#[source]
|
#[source]
|
||||||
|
|
@ -158,6 +160,7 @@ impl Error {
|
||||||
if let Some(missing_library) = missing_library {
|
if let Some(missing_library) = missing_library {
|
||||||
return Self::MissingHeader {
|
return Self::MissingHeader {
|
||||||
message,
|
message,
|
||||||
|
exit_code: output.status,
|
||||||
stdout,
|
stdout,
|
||||||
stderr,
|
stderr,
|
||||||
missing_header_cause: MissingHeaderCause {
|
missing_header_cause: MissingHeaderCause {
|
||||||
|
|
@ -169,6 +172,7 @@ impl Error {
|
||||||
|
|
||||||
Self::BuildBackend {
|
Self::BuildBackend {
|
||||||
message,
|
message,
|
||||||
|
exit_code: output.status,
|
||||||
stdout,
|
stdout,
|
||||||
stderr,
|
stderr,
|
||||||
}
|
}
|
||||||
|
|
@ -968,8 +972,10 @@ mod test {
|
||||||
"pygraphviz-1.11",
|
"pygraphviz-1.11",
|
||||||
);
|
);
|
||||||
assert!(matches!(err, Error::MissingHeader { .. }));
|
assert!(matches!(err, Error::MissingHeader { .. }));
|
||||||
insta::assert_snapshot!(err, @r###"
|
// Unix uses exit status, Windows uses exit code.
|
||||||
Failed building wheel through setup.py:
|
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:
|
--- stdout:
|
||||||
running bdist_wheel
|
running bdist_wheel
|
||||||
running build
|
running build
|
||||||
|
|
@ -1018,8 +1024,10 @@ mod test {
|
||||||
"pygraphviz-1.11",
|
"pygraphviz-1.11",
|
||||||
);
|
);
|
||||||
assert!(matches!(err, Error::MissingHeader { .. }));
|
assert!(matches!(err, Error::MissingHeader { .. }));
|
||||||
insta::assert_snapshot!(err, @r###"
|
// Unix uses exit status, Windows uses exit code.
|
||||||
Failed building wheel through setup.py:
|
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:
|
--- stdout:
|
||||||
|
|
||||||
--- stderr:
|
--- stderr:
|
||||||
|
|
|
||||||
|
|
@ -507,6 +507,7 @@ impl InterpreterInfo {
|
||||||
interpreter.display(),
|
interpreter.display(),
|
||||||
output.status,
|
output.status,
|
||||||
),
|
),
|
||||||
|
exit_code: output.status,
|
||||||
stdout: String::from_utf8_lossy(&output.stdout).trim().to_string(),
|
stdout: String::from_utf8_lossy(&output.stdout).trim().to_string(),
|
||||||
stderr: String::from_utf8_lossy(&output.stderr).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}",
|
"Querying Python at `{}` did not return the expected data: {err}",
|
||||||
interpreter.display(),
|
interpreter.display(),
|
||||||
),
|
),
|
||||||
|
exit_code: output.status,
|
||||||
stdout: String::from_utf8_lossy(&output.stdout).trim().to_string(),
|
stdout: String::from_utf8_lossy(&output.stdout).trim().to_string(),
|
||||||
stderr: String::from_utf8_lossy(&output.stderr).trim().to_string(),
|
stderr: String::from_utf8_lossy(&output.stderr).trim().to_string(),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::process::ExitStatus;
|
||||||
|
|
||||||
use thiserror::Error;
|
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?"
|
"Could not find `python.exe` through `py --list-paths` or in 'PATH'. Is Python installed?"
|
||||||
)]
|
)]
|
||||||
NoPythonInstalledWindows,
|
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 {
|
PythonSubcommandOutput {
|
||||||
message: String,
|
message: String,
|
||||||
|
exit_code: ExitStatus,
|
||||||
stdout: String,
|
stdout: String,
|
||||||
stderr: String,
|
stderr: String,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -442,6 +442,7 @@ mod windows {
|
||||||
"Running `py --list-paths` failed with status {}",
|
"Running `py --list-paths` failed with status {}",
|
||||||
output.status
|
output.status
|
||||||
),
|
),
|
||||||
|
exit_code: output.status,
|
||||||
stdout: String::from_utf8_lossy(&output.stdout).trim().to_string(),
|
stdout: String::from_utf8_lossy(&output.stdout).trim().to_string(),
|
||||||
stderr: String::from_utf8_lossy(&output.stderr).trim().to_string(),
|
stderr: String::from_utf8_lossy(&output.stderr).trim().to_string(),
|
||||||
});
|
});
|
||||||
|
|
@ -451,6 +452,7 @@ mod windows {
|
||||||
let stdout =
|
let stdout =
|
||||||
String::from_utf8(output.stdout).map_err(|err| Error::PythonSubcommandOutput {
|
String::from_utf8(output.stdout).map_err(|err| Error::PythonSubcommandOutput {
|
||||||
message: format!("The stdout of `py --list-paths` isn't UTF-8 encoded: {err}"),
|
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(),
|
stdout: String::from_utf8_lossy(err.as_bytes()).trim().to_string(),
|
||||||
stderr: String::from_utf8_lossy(&output.stderr).trim().to_string(),
|
stderr: String::from_utf8_lossy(&output.stderr).trim().to_string(),
|
||||||
})?;
|
})?;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue