From ed1684a0e4caee45482098666da124b5aa195b5c Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Thu, 26 Sep 2024 18:39:47 -0500 Subject: [PATCH] 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? --- crates/uv-cli/src/lib.rs | 7 ++++++ crates/uv/src/commands/build.rs | 11 +++++++++- crates/uv/src/lib.rs | 1 + crates/uv/src/settings.rs | 4 ++++ crates/uv/tests/build.rs | 38 +++++++++++++++++++++++++++++++++ 5 files changed, 60 insertions(+), 1 deletion(-) diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index 68b4dba9a..111e59ae0 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -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. /// diff --git a/crates/uv/src/commands/build.rs b/crates/uv/src/commands/build.rs index 1f0ff9e5e..dd41444d2 100644 --- a/crates/uv/src/commands/build.rs +++ b/crates/uv/src/commands/build.rs @@ -38,6 +38,7 @@ pub(crate) async fn build( output_dir: Option, sdist: bool, wheel: bool, + build_logs: bool, build_constraints: Vec, hash_checking: Option, python: Option, @@ -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, 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, }; diff --git a/crates/uv/src/lib.rs b/crates/uv/src/lib.rs index 983bc3c2b..dd0f0905b 100644 --- a/crates/uv/src/lib.rs +++ b/crates/uv/src/lib.rs @@ -686,6 +686,7 @@ async fn run(cli: Cli) -> Result { args.out_dir, args.sdist, args.wheel, + args.build_logs, build_constraints, args.hash_checking, args.python, diff --git a/crates/uv/src/settings.rs b/crates/uv/src/settings.rs index fb924949e..c7378babe 100644 --- a/crates/uv/src/settings.rs +++ b/crates/uv/src/settings.rs @@ -1674,6 +1674,7 @@ pub(crate) struct BuildSettings { pub(crate) out_dir: Option, pub(crate) sdist: bool, pub(crate) wheel: bool, + pub(crate) build_logs: bool, pub(crate) build_constraint: Vec, pub(crate) hash_checking: Option, pub(crate) python: Option, @@ -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) diff --git a/crates/uv/tests/build.rs b/crates/uv/tests/build.rs index 31110be6c..757509c85 100644 --- a/crates/uv/tests/build.rs +++ b/crates/uv/tests/build.rs @@ -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(()) +}