Skip to content

Commit 31bed1d

Browse files
committed
Add UV_HIDE_BUILD_OUTPUT to omit build logs
1 parent 5498e4d commit 31bed1d

9 files changed

Lines changed: 126 additions & 3 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/uv-distribution/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ uv-configuration = { workspace = true }
2424
uv-distribution-filename = { workspace = true }
2525
uv-distribution-types = { workspace = true }
2626
uv-extract = { workspace = true }
27+
uv-flags = { workspace = true }
2728
uv-fs = { workspace = true, features = ["tokio"] }
2829
uv-git = { workspace = true }
2930
uv-git-types = { workspace = true }

crates/uv-distribution/src/source/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,7 +2474,11 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
24742474
} else {
24752475
BuildKind::Wheel
24762476
},
2477-
BuildOutput::Debug,
2477+
if uv_flags::contains(uv_flags::EnvironmentFlags::HIDE_BUILD_OUTPUT) {
2478+
BuildOutput::Quiet
2479+
} else {
2480+
BuildOutput::Debug
2481+
},
24782482
self.build_stack.cloned().unwrap_or_default(),
24792483
)
24802484
.await
@@ -2575,7 +2579,11 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
25752579
source.as_dist(),
25762580
source_strategy,
25772581
build_kind,
2578-
BuildOutput::Debug,
2582+
if uv_flags::contains(uv_flags::EnvironmentFlags::HIDE_BUILD_OUTPUT) {
2583+
BuildOutput::Quiet
2584+
} else {
2585+
BuildOutput::Debug
2586+
},
25792587
self.build_stack.cloned().unwrap_or_default(),
25802588
)
25812589
.await

crates/uv-flags/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ bitflags::bitflags! {
66
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
77
pub struct EnvironmentFlags: u32 {
88
const SKIP_WHEEL_FILENAME_CHECK = 1 << 0;
9+
const HIDE_BUILD_OUTPUT = 1 << 1;
910
}
1011
}
1112

crates/uv-settings/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ pub struct Concurrency {
585585
#[derive(Debug, Clone)]
586586
pub struct EnvironmentOptions {
587587
pub skip_wheel_filename_check: Option<bool>,
588+
pub hide_build_output: Option<bool>,
588589
pub python_install_bin: Option<bool>,
589590
pub python_install_registry: Option<bool>,
590591
pub install_mirrors: PythonInstallMirrors,
@@ -613,6 +614,7 @@ impl EnvironmentOptions {
613614
skip_wheel_filename_check: parse_boolish_environment_variable(
614615
EnvVars::UV_SKIP_WHEEL_FILENAME_CHECK,
615616
)?,
617+
hide_build_output: parse_boolish_environment_variable(EnvVars::UV_HIDE_BUILD_OUTPUT)?,
616618
python_install_bin: parse_boolish_environment_variable(EnvVars::UV_PYTHON_INSTALL_BIN)?,
617619
python_install_registry: parse_boolish_environment_variable(
618620
EnvVars::UV_PYTHON_INSTALL_REGISTRY,
@@ -775,6 +777,9 @@ impl From<&EnvironmentOptions> for EnvironmentFlags {
775777
if options.skip_wheel_filename_check == Some(true) {
776778
flags.insert(Self::SKIP_WHEEL_FILENAME_CHECK);
777779
}
780+
if options.hide_build_output == Some(true) {
781+
flags.insert(Self::HIDE_BUILD_OUTPUT);
782+
}
778783
flags
779784
}
780785
}

crates/uv-static/src/env_vars.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,4 +1215,9 @@ impl EnvVars {
12151215
/// around invalid artifacts in rare cases.
12161216
#[attr_added_in("0.8.23")]
12171217
pub const UV_SKIP_WHEEL_FILENAME_CHECK: &'static str = "UV_SKIP_WHEEL_FILENAME_CHECK";
1218+
1219+
/// Suppress output from the build backend when building source distributions, even in the event
1220+
/// of build failures.
1221+
#[attr_added_in("0.9.14")]
1222+
pub const UV_HIDE_BUILD_OUTPUT: &'static str = "UV_HIDE_BUILD_OUTPUT";
12181223
}

crates/uv/src/commands/build_frontend.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ async fn build_package(
663663

664664
let build_output = match printer {
665665
Printer::Default | Printer::NoProgress | Printer::Verbose => {
666-
if build_logs {
666+
if build_logs && !uv_flags::contains(uv_flags::EnvironmentFlags::HIDE_BUILD_OUTPUT) {
667667
BuildOutput::Stderr
668668
} else {
669669
BuildOutput::Quiet

crates/uv/tests/it/build.rs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,102 @@ fn build_no_build_logs() -> Result<()> {
11801180
Ok(())
11811181
}
11821182

1183+
/// Test that `UV_HIDE_BUILD_OUTPUT` suppresses build output.
1184+
#[test]
1185+
fn build_hide_build_output_env_var() -> Result<()> {
1186+
let context = TestContext::new("3.12");
1187+
1188+
let project = context.temp_dir.child("project");
1189+
1190+
let pyproject_toml = project.child("pyproject.toml");
1191+
pyproject_toml.write_str(
1192+
r#"
1193+
[project]
1194+
name = "project"
1195+
version = "0.1.0"
1196+
requires-python = ">=3.12"
1197+
dependencies = ["anyio==3.7.0"]
1198+
1199+
[build-system]
1200+
requires = ["hatchling"]
1201+
build-backend = "hatchling.build"
1202+
"#,
1203+
)?;
1204+
1205+
project
1206+
.child("src")
1207+
.child("project")
1208+
.child("__init__.py")
1209+
.touch()?;
1210+
project.child("README").touch()?;
1211+
1212+
uv_snapshot!(&context.filters(), context.build().arg("project").env(EnvVars::UV_HIDE_BUILD_OUTPUT, "1"), @r###"
1213+
success: true
1214+
exit_code: 0
1215+
----- stdout -----
1216+
1217+
----- stderr -----
1218+
Building source distribution...
1219+
Building wheel from source distribution...
1220+
Successfully built project/dist/project-0.1.0.tar.gz
1221+
Successfully built project/dist/project-0.1.0-py3-none-any.whl
1222+
"###);
1223+
1224+
Ok(())
1225+
}
1226+
1227+
/// Test that `UV_HIDE_BUILD_OUTPUT` hides build output even on failure.
1228+
#[test]
1229+
fn build_hide_build_output_on_failure() -> Result<()> {
1230+
let context = TestContext::new("3.12");
1231+
let filters = context
1232+
.filters()
1233+
.into_iter()
1234+
.chain([(r"\\\.", "")])
1235+
.collect::<Vec<_>>();
1236+
1237+
let project = context.temp_dir.child("project");
1238+
1239+
let pyproject_toml = project.child("pyproject.toml");
1240+
pyproject_toml.write_str(
1241+
r#"
1242+
[project]
1243+
name = "project"
1244+
version = "0.1.0"
1245+
requires-python = ">=3.12"
1246+
1247+
[build-system]
1248+
requires = ["setuptools"]
1249+
build-backend = "setuptools.build_meta"
1250+
"#,
1251+
)?;
1252+
1253+
// Create a `setup.py` that prints an environment variable before failing.
1254+
project.child("setup.py").write_str(indoc! {r#"
1255+
import os
1256+
import sys
1257+
print("FOO=" + os.environ.get("FOO", "not-set"), file=sys.stderr)
1258+
sys.stderr.flush()
1259+
raise Exception("Build failed intentionally!")
1260+
"#})?;
1261+
1262+
// With `UV_HIDE_BUILD_OUTPUT`, the output is hidden even on failure.
1263+
uv_snapshot!(&filters, context.build().arg("project").env(EnvVars::UV_HIDE_BUILD_OUTPUT, "1").env("FOO", "bar"), @r###"
1264+
success: false
1265+
exit_code: 2
1266+
----- stdout -----
1267+
1268+
----- stderr -----
1269+
Building source distribution...
1270+
× Failed to build `[TEMP_DIR]/project`
1271+
├─▶ The build backend returned an error
1272+
╰─▶ Call to `setuptools.build_meta.build_sdist` failed (exit status: 1)
1273+
hint: This usually indicates a problem with the package or the build environment.
1274+
"###);
1275+
1276+
Ok(())
1277+
}
1278+
11831279
#[test]
11841280
fn build_tool_uv_sources() -> Result<()> {
11851281
let context = TestContext::new("3.12");

docs/reference/environment.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ Equivalent to the `--token` argument for self update. A GitHub token for authent
150150

151151
Enables fetching files stored in Git LFS when installing a package from a Git repository.
152152

153+
### `UV_HIDE_BUILD_OUTPUT`
154+
<small class="added-in">added in `0.9.14`</small>
155+
156+
Suppress output from the build backend when building source distributions, even in the event
157+
of build failures.
158+
153159
### `UV_HTTP_RETRIES`
154160
<small class="added-in">added in `0.7.21`</small>
155161

0 commit comments

Comments
 (0)