Skip to content

Commit d336b8f

Browse files
authored
Silence stdout/stderr during Pants setup. (#375)
Closes pantsbuild/pants#20315 Broken out from #351
1 parent 667facd commit d336b8f

File tree

7 files changed

+97
-31
lines changed

7 files changed

+97
-31
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
name: CI
22
on:
33
push:
4+
# Ignore non top-level branches.
45
branches-ignore:
5-
- dependabot/**
6+
- '*/**'
67
pull_request:
78
defaults:
89
run:

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Release Notes
22

3+
## 0.10.8
4+
5+
Redirect pants install messages to a `pants-install.log` file in pants venv directory to not pollute
6+
stdout/stderr.
7+
38
## 0.10.7
49

510
This release upgrades `pex` to `v2.1.163` and the bootstrap Python to `3.9.18`.

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ members = [
66
[package]
77
name = "scie-pants"
88
description = "Protects your Pants from the elements."
9-
version = "0.10.7"
9+
version = "0.10.8"
1010
edition = "2021"
1111
authors = [
1212
"John Sirois <[email protected]>",

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ That will update to the latest available stable release if there is a newer one
125125
there is not. You can also supply a `scie-pants` version as the sole argument to downgrade or switch
126126
to a specific version.
127127

128+
### Check pants installation logs
129+
130+
When the Python virtual environment (venv) for Pants is created, any logged output during that
131+
process is saved in a `pants-install.log` file in the venv root. The path to the venv root is logged
132+
during bootstrapping on a line with this pattern:
133+
134+
New virtual environment successfully created at /.../nce/<hash value>/bindings/venvs/<pants version>
135+
136+
128137
### Report an issue
129138

130139
You can report an issue directly at https://github.com/pantsbuild/scie-pants/issues. Please include

package/src/test.rs

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,17 @@ macro_rules! integration_test {
2929
};
3030
}
3131

32-
fn issue_link(issue: usize) -> String {
33-
format!("https://github.com/pantsbuild/scie-pants/issues/{issue}")
32+
macro_rules! issue_link {
33+
($issue: expr) => {
34+
issue_link($issue, "pantsbuild/scie-pants")
35+
};
36+
($issue: expr, $repo: expr) => {
37+
issue_link($issue, $repo)
38+
};
39+
}
40+
41+
fn issue_link(issue: usize, repo: &str) -> String {
42+
format!("https://github.com/{repo}/issues/{issue}")
3443
}
3544

3645
fn decode_output(output: Vec<u8>) -> Result<String> {
@@ -99,6 +108,7 @@ pub(crate) fn run_integration_tests(
99108
test_tools(scie_pants_scie, check);
100109
test_pants_bin_name_handling(scie_pants_scie);
101110
test_pants_bootstrap_handling(scie_pants_scie);
111+
test_pants_bootstrap_stdout_silent(scie_pants_scie);
102112
test_tools_pex_reproducibility(workspace_root, tools_pex_path, tools_pex_mismatch_warn);
103113
test_pants_bootstrap_tools(scie_pants_scie);
104114

@@ -238,7 +248,7 @@ fn test_pants_bin_name_handling(scie_pants_scie: &Path) {
238248
false,
239249
r#"
240250
[GLOBAL]
241-
pants_version = "2.15.0rc5"
251+
pants_version = "2.18.0"
242252
[anonymous-telemetry]
243253
enabled = false
244254
"#,
@@ -408,7 +418,7 @@ fn test_ignore_empty_pants_version_pants_sha(scie_pants_scie: &Path) {
408418

409419
let tmpdir = create_tempdir().unwrap();
410420

411-
let pants_release = "2.15.0";
421+
let pants_release = "2.18.0";
412422
let pants_toml_content = format!(
413423
r#"
414424
[GLOBAL]
@@ -437,7 +447,7 @@ fn test_pants_from_pex_version(scie_pants_scie: &Path) {
437447

438448
let tmpdir = create_tempdir().unwrap();
439449

440-
let pants_release = "2.18.0.dev5";
450+
let pants_release = "2.18.0";
441451
let pants_toml_content = format!(
442452
r#"
443453
[GLOBAL]
@@ -816,15 +826,15 @@ fn test_self_downgrade(scie_pants_scie: &Path) {
816826
fn test_caching_issue_129(scie_pants_scie: &Path) {
817827
integration_test!(
818828
"Verifying the build root does not influence caching ({issue})",
819-
issue = issue_link(129)
829+
issue = issue_link!(129)
820830
);
821831
let tmpdir = create_tempdir().unwrap();
822832

823833
let scie_base = tmpdir.path().join("nce");
824834

825835
let pants_toml = r#"
826836
[GLOBAL]
827-
pants_version = "2.15.0"
837+
pants_version = "2.18.0"
828838
[anonymous-telemetry]
829839
enabled = false
830840
"#;
@@ -894,7 +904,7 @@ fn test_caching_issue_129(scie_pants_scie: &Path) {
894904
fn test_custom_pants_toml_issue_153(scie_pants_scie: &Path) {
895905
integration_test!(
896906
"Verifying the PANTS_TOML env var is respected ({issue})",
897-
issue = issue_link(153)
907+
issue = issue_link!(153)
898908
);
899909

900910
let tmpdir = create_tempdir().unwrap();
@@ -978,7 +988,7 @@ fn test_pants_native_client_perms_issue_182(scie_pants_scie: &Path) {
978988
integration_test!(
979989
"Verifying scie-pants sets executable perms on the Pants native client binary when \
980990
present ({issue})",
981-
issue = issue_link(182)
991+
issue = issue_link!(182)
982992
);
983993

984994
let tmpdir = create_tempdir().unwrap();
@@ -1009,7 +1019,7 @@ fn test_pants_native_client_perms_issue_182(scie_pants_scie: &Path) {
10091019
fn test_non_utf8_env_vars_issue_198(scie_pants_scie: &Path) {
10101020
integration_test!(
10111021
"Verifying scie-pants is robust to environments with non-utf8 env vars present ({issue})",
1012-
issue = issue_link(198)
1022+
issue = issue_link!(198)
10131023
);
10141024

10151025
let tmpdir = create_tempdir().unwrap();
@@ -1112,7 +1122,7 @@ fn test_bad_boot_error_text(scie_pants_scie: &Path) {
11121122
fn test_pants_bootstrap_urls(scie_pants_scie: &Path) {
11131123
integration_test!(
11141124
"Verifying PANTS_BOOTSTRAP_URLS is used for both CPython interpreter and Pants PEX ({issue})",
1115-
issue = issue_link(243)
1125+
issue = issue_link!(243)
11161126
);
11171127

11181128
// This test runs in 4 parts:
@@ -1224,3 +1234,30 @@ fn test_pants_bootstrap_urls(scie_pants_scie: &Path) {
12241234
let stdout = decode_output(output.stdout).unwrap();
12251235
assert!(stdout.contains(pants_release));
12261236
}
1237+
1238+
fn test_pants_bootstrap_stdout_silent(scie_pants_scie: &Path) {
1239+
integration_test!(
1240+
"Verifying scie-pants bootstraps Pants without any output on stdout ({issue})",
1241+
issue = issue_link!(20315, "pantsbuild/pants")
1242+
);
1243+
// Bootstrap a new unseen version of Pants to verify there is no extra output on stdout besides
1244+
// the requested output from the pants command.
1245+
let (output, _stderr) = assert_stderr_output(
1246+
Command::new(scie_pants_scie)
1247+
.arg("-V")
1248+
.env("PANTS_VERSION", "2.19.1")
1249+
.stdout(Stdio::piped()),
1250+
// Expect bootstrap messages to ensure we actually bootstrapped pants during this execution.
1251+
vec![
1252+
"Bootstrapping Pants 2.19.1",
1253+
"Installing pantsbuild.pants==2.19.1 into a virtual environment at ",
1254+
"New virtual environment successfully created at ",
1255+
],
1256+
ExpectedResult::Success,
1257+
);
1258+
let stdout = decode_output(output.stdout).unwrap();
1259+
assert!(
1260+
stdout.eq("2.19.1\n"),
1261+
"STDOUT was not '2.19.1':\n{stdout}\n"
1262+
);
1263+
}

tools/src/scie_pants/install_pants.py

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,23 +120,37 @@ def install_pants_from_pex(
120120
" or file an issue on GitHub: https://github.com/pantsbuild/pants/issues/new/choose.\n\n"
121121
f"Exception:\n\n{e}"
122122
)
123-
subprocess.run(
124-
args=[
125-
sys.executable,
126-
pants_pex.name,
127-
"venv",
128-
"--prompt",
129-
prompt,
130-
"--compile",
131-
"--pip",
132-
"--collisions-ok",
133-
"--no-emit-warnings", # Silence `PEXWarning: You asked for --pip ...`
134-
"--disable-cache",
135-
str(venv_dir),
136-
],
137-
env={"PEX_TOOLS": "1"},
138-
check=True,
139-
)
123+
try:
124+
pants_venv_result = subprocess.run(
125+
args=[
126+
sys.executable,
127+
pants_pex.name,
128+
"venv",
129+
"--prompt",
130+
prompt,
131+
"--compile",
132+
"--pip",
133+
"--collisions-ok",
134+
"--no-emit-warnings", # Silence `PEXWarning: You asked for --pip ...`
135+
"--disable-cache",
136+
str(venv_dir),
137+
],
138+
env={"PEX_TOOLS": "1"},
139+
check=True,
140+
stdout=subprocess.PIPE,
141+
stderr=subprocess.STDOUT,
142+
)
143+
except subprocess.CalledProcessError as e:
144+
fatal(
145+
f"Failed to create Pants virtual environment.\nError: {e}, output:"
146+
f"\n-----\n{e.stdout}\n-----\n"
147+
)
148+
else:
149+
with open(str(venv_dir / "pants-install.log"), "a") as fp:
150+
print(f"Installed {pex_name}", file=fp)
151+
if pants_venv_result.stdout:
152+
print(pants_venv_result.stdout.decode(), file=fp)
153+
print("\n-----", file=fp)
140154

141155
if extra_requirements:
142156
venv_pip_install(

0 commit comments

Comments
 (0)