Skip to content

Commit

Permalink
Silence stdout/stderr during Pants setup. (#375)
Browse files Browse the repository at this point in the history
Closes pantsbuild/pants#20315
Broken out from #351
  • Loading branch information
kaos committed Mar 18, 2024
1 parent 667facd commit d336b8f
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: CI
on:
push:
# Ignore non top-level branches.
branches-ignore:
- dependabot/**
- '*/**'
pull_request:
defaults:
run:
Expand Down
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes

## 0.10.8

Redirect pants install messages to a `pants-install.log` file in pants venv directory to not pollute
stdout/stderr.

## 0.10.7

This release upgrades `pex` to `v2.1.163` and the bootstrap Python to `3.9.18`.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = [
[package]
name = "scie-pants"
description = "Protects your Pants from the elements."
version = "0.10.7"
version = "0.10.8"
edition = "2021"
authors = [
"John Sirois <john.sirois@gmail.com>",
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ That will update to the latest available stable release if there is a newer one
there is not. You can also supply a `scie-pants` version as the sole argument to downgrade or switch
to a specific version.

### Check pants installation logs

When the Python virtual environment (venv) for Pants is created, any logged output during that
process is saved in a `pants-install.log` file in the venv root. The path to the venv root is logged
during bootstrapping on a line with this pattern:

New virtual environment successfully created at /.../nce/<hash value>/bindings/venvs/<pants version>


### Report an issue

You can report an issue directly at https://github.com/pantsbuild/scie-pants/issues. Please include
Expand Down
59 changes: 48 additions & 11 deletions package/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,17 @@ macro_rules! integration_test {
};
}

fn issue_link(issue: usize) -> String {
format!("https://github.com/pantsbuild/scie-pants/issues/{issue}")
macro_rules! issue_link {
($issue: expr) => {
issue_link($issue, "pantsbuild/scie-pants")
};
($issue: expr, $repo: expr) => {
issue_link($issue, $repo)
};
}

fn issue_link(issue: usize, repo: &str) -> String {
format!("https://github.com/{repo}/issues/{issue}")
}

fn decode_output(output: Vec<u8>) -> Result<String> {
Expand Down Expand Up @@ -99,6 +108,7 @@ pub(crate) fn run_integration_tests(
test_tools(scie_pants_scie, check);
test_pants_bin_name_handling(scie_pants_scie);
test_pants_bootstrap_handling(scie_pants_scie);
test_pants_bootstrap_stdout_silent(scie_pants_scie);
test_tools_pex_reproducibility(workspace_root, tools_pex_path, tools_pex_mismatch_warn);
test_pants_bootstrap_tools(scie_pants_scie);

Expand Down Expand Up @@ -238,7 +248,7 @@ fn test_pants_bin_name_handling(scie_pants_scie: &Path) {
false,
r#"
[GLOBAL]
pants_version = "2.15.0rc5"
pants_version = "2.18.0"
[anonymous-telemetry]
enabled = false
"#,
Expand Down Expand Up @@ -408,7 +418,7 @@ fn test_ignore_empty_pants_version_pants_sha(scie_pants_scie: &Path) {

let tmpdir = create_tempdir().unwrap();

let pants_release = "2.15.0";
let pants_release = "2.18.0";
let pants_toml_content = format!(
r#"
[GLOBAL]
Expand Down Expand Up @@ -437,7 +447,7 @@ fn test_pants_from_pex_version(scie_pants_scie: &Path) {

let tmpdir = create_tempdir().unwrap();

let pants_release = "2.18.0.dev5";
let pants_release = "2.18.0";
let pants_toml_content = format!(
r#"
[GLOBAL]
Expand Down Expand Up @@ -816,15 +826,15 @@ fn test_self_downgrade(scie_pants_scie: &Path) {
fn test_caching_issue_129(scie_pants_scie: &Path) {
integration_test!(
"Verifying the build root does not influence caching ({issue})",
issue = issue_link(129)
issue = issue_link!(129)
);
let tmpdir = create_tempdir().unwrap();

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

let pants_toml = r#"
[GLOBAL]
pants_version = "2.15.0"
pants_version = "2.18.0"
[anonymous-telemetry]
enabled = false
"#;
Expand Down Expand Up @@ -894,7 +904,7 @@ fn test_caching_issue_129(scie_pants_scie: &Path) {
fn test_custom_pants_toml_issue_153(scie_pants_scie: &Path) {
integration_test!(
"Verifying the PANTS_TOML env var is respected ({issue})",
issue = issue_link(153)
issue = issue_link!(153)
);

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

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

let tmpdir = create_tempdir().unwrap();
Expand Down Expand Up @@ -1112,7 +1122,7 @@ fn test_bad_boot_error_text(scie_pants_scie: &Path) {
fn test_pants_bootstrap_urls(scie_pants_scie: &Path) {
integration_test!(
"Verifying PANTS_BOOTSTRAP_URLS is used for both CPython interpreter and Pants PEX ({issue})",
issue = issue_link(243)
issue = issue_link!(243)
);

// This test runs in 4 parts:
Expand Down Expand Up @@ -1224,3 +1234,30 @@ fn test_pants_bootstrap_urls(scie_pants_scie: &Path) {
let stdout = decode_output(output.stdout).unwrap();
assert!(stdout.contains(pants_release));
}

fn test_pants_bootstrap_stdout_silent(scie_pants_scie: &Path) {
integration_test!(
"Verifying scie-pants bootstraps Pants without any output on stdout ({issue})",
issue = issue_link!(20315, "pantsbuild/pants")
);
// Bootstrap a new unseen version of Pants to verify there is no extra output on stdout besides
// the requested output from the pants command.
let (output, _stderr) = assert_stderr_output(
Command::new(scie_pants_scie)
.arg("-V")
.env("PANTS_VERSION", "2.19.1")
.stdout(Stdio::piped()),
// Expect bootstrap messages to ensure we actually bootstrapped pants during this execution.
vec![
"Bootstrapping Pants 2.19.1",
"Installing pantsbuild.pants==2.19.1 into a virtual environment at ",
"New virtual environment successfully created at ",
],
ExpectedResult::Success,
);
let stdout = decode_output(output.stdout).unwrap();
assert!(
stdout.eq("2.19.1\n"),
"STDOUT was not '2.19.1':\n{stdout}\n"
);
}
48 changes: 31 additions & 17 deletions tools/src/scie_pants/install_pants.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,37 @@ def install_pants_from_pex(
" or file an issue on GitHub: https://github.com/pantsbuild/pants/issues/new/choose.\n\n"
f"Exception:\n\n{e}"
)
subprocess.run(
args=[
sys.executable,
pants_pex.name,
"venv",
"--prompt",
prompt,
"--compile",
"--pip",
"--collisions-ok",
"--no-emit-warnings", # Silence `PEXWarning: You asked for --pip ...`
"--disable-cache",
str(venv_dir),
],
env={"PEX_TOOLS": "1"},
check=True,
)
try:
pants_venv_result = subprocess.run(
args=[
sys.executable,
pants_pex.name,
"venv",
"--prompt",
prompt,
"--compile",
"--pip",
"--collisions-ok",
"--no-emit-warnings", # Silence `PEXWarning: You asked for --pip ...`
"--disable-cache",
str(venv_dir),
],
env={"PEX_TOOLS": "1"},
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
except subprocess.CalledProcessError as e:
fatal(
f"Failed to create Pants virtual environment.\nError: {e}, output:"
f"\n-----\n{e.stdout}\n-----\n"
)
else:
with open(str(venv_dir / "pants-install.log"), "a") as fp:
print(f"Installed {pex_name}", file=fp)
if pants_venv_result.stdout:
print(pants_venv_result.stdout.decode(), file=fp)
print("\n-----", file=fp)

if extra_requirements:
venv_pip_install(
Expand Down

0 comments on commit d336b8f

Please sign in to comment.