Add uv build --no-build-logs to silence the build backend logs (#7675)

Extends https://github.com/astral-sh/uv/pull/7674

The build backend can be pretty verbose, it seems nice to be able to
turn that off?
This commit is contained in:
Zanie Blue 2024-09-26 18:39:47 -05:00 committed by GitHub
parent 3ce34035c8
commit ed1684a0e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 60 additions and 1 deletions

View file

@ -2029,6 +2029,13 @@ pub struct BuildArgs {
#[arg(long)]
pub wheel: bool,
#[arg(long, overrides_with("no_build_logs"), hide = true)]
pub build_logs: bool,
/// Hide logs from the build backend.
#[arg(long, overrides_with("build_logs"), hide = true)]
pub no_build_logs: bool,
/// Constrain build dependencies using the given requirements files when building
/// distributions.
///

View file

@ -38,6 +38,7 @@ pub(crate) async fn build(
output_dir: Option<PathBuf>,
sdist: bool,
wheel: bool,
build_logs: bool,
build_constraints: Vec<RequirementsSource>,
hash_checking: Option<HashCheckingMode>,
python: Option<String>,
@ -58,6 +59,7 @@ pub(crate) async fn build(
output_dir.as_deref(),
sdist,
wheel,
build_logs,
&build_constraints,
hash_checking,
python.as_deref(),
@ -109,6 +111,7 @@ async fn build_impl(
output_dir: Option<&Path>,
sdist: bool,
wheel: bool,
build_logs: bool,
build_constraints: &[RequirementsSource],
hash_checking: Option<HashCheckingMode>,
python_request: Option<&str>,
@ -369,7 +372,13 @@ async fn build_impl(
let dist = None;
let build_output = match printer {
Printer::Default | Printer::NoProgress | Printer::Verbose => BuildOutput::Stderr,
Printer::Default | Printer::NoProgress | Printer::Verbose => {
if build_logs {
BuildOutput::Stderr
} else {
BuildOutput::Quiet
}
}
Printer::Quiet => BuildOutput::Quiet,
};

View file

@ -686,6 +686,7 @@ async fn run(cli: Cli) -> Result<ExitStatus> {
args.out_dir,
args.sdist,
args.wheel,
args.build_logs,
build_constraints,
args.hash_checking,
args.python,

View file

@ -1674,6 +1674,7 @@ pub(crate) struct BuildSettings {
pub(crate) out_dir: Option<PathBuf>,
pub(crate) sdist: bool,
pub(crate) wheel: bool,
pub(crate) build_logs: bool,
pub(crate) build_constraint: Vec<PathBuf>,
pub(crate) hash_checking: Option<HashCheckingMode>,
pub(crate) python: Option<String>,
@ -1695,6 +1696,8 @@ impl BuildSettings {
no_require_hashes,
verify_hashes,
no_verify_hashes,
build_logs,
no_build_logs,
python,
build,
refresh,
@ -1707,6 +1710,7 @@ impl BuildSettings {
out_dir,
sdist,
wheel,
build_logs: flag(build_logs, no_build_logs).unwrap_or(true),
build_constraint: build_constraint
.into_iter()
.filter_map(Maybe::into_option)

View file

@ -1521,3 +1521,41 @@ fn build_quiet() -> Result<()> {
Ok(())
}
#[test]
fn build_no_build_logs() -> Result<()> {
let context = TestContext::new("3.12");
let project = context.temp_dir.child("project");
let pyproject_toml = project.child("pyproject.toml");
pyproject_toml.write_str(
r#"
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["anyio==3.7.0"]
[build-system]
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"
"#,
)?;
project.child("src").child("__init__.py").touch()?;
project.child("README").touch()?;
uv_snapshot!(&context.filters(), context.build().arg("project").arg("--no-build-logs"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Building source distribution...
Building wheel from source distribution...
Successfully built project/dist/project-0.1.0.tar.gz and project/dist/project-0.1.0-py3-none-any.whl
"###);
Ok(())
}