Skip to content

Commit 78628db

Browse files
authored
Improve Pants help output / CLI fidelity. (#112)
Previously scie-pants over-rode Pants help defaulting to `./pants` in help text by passing `--pants-bin-name` as the absolute path of scie-pants. Now scie-pants passes the exact argv0 string it was invoked with and it does so using the `PANTS_BIN_NAME` env var instead of `--pants-bin-name` to support users over-riding this. Closes #111
1 parent af3c783 commit 78628db

File tree

6 files changed

+80
-5
lines changed

6 files changed

+80
-5
lines changed

CHANGES.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Release Notes
22

3+
## 0.5.0
4+
5+
This release improves `scie-pants` operation with Pants help by ensuring the command line you used
6+
to invoke Pants is accurately reflected in the help information Pants presents back to you.
7+
38
## 0.4.2
49

510
This release fixes `.pants.bootstrap` handling to robustly mimic handling by the `./pants` script.

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
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.4.2"
9+
version = "0.5.0"
1010
edition = "2021"
1111
authors = [
1212
"John Sirois <[email protected]>",

package/scie-pants.lift.json

-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
},
9797
"exe": "{scie.bindings.install:VIRTUAL_ENV}/bin/pants",
9898
"args": [
99-
"--pants-bin-name={scie.env.PANTS_BIN_NAME}",
10099
"{scie.bindings.configure:PANTS_SHA_FIND_LINKS}"
101100
]
102101
},
@@ -114,7 +113,6 @@
114113
"127.0.0.1:5678",
115114
"--wait-for-client",
116115
"{scie.bindings.install:VIRTUAL_ENV}/bin/pants",
117-
"--pants-bin-name={scie.env.PANTS_BIN_NAME}",
118116
"{scie.bindings.configure:PANTS_SHA_FIND_LINKS}"
119117
]
120118
},

package/src/main.rs

+68
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,74 @@ fn test(
827827
.env("EXPECTED_LINES", tput_output("lines")?.trim()),
828828
)?;
829829

830+
integration_test!("Checking PANTS_BIN_NAME handling");
831+
{
832+
let check_pants_bin_name_chroot = create_tempdir()?;
833+
834+
let bin_dir = check_pants_bin_name_chroot.path().join("bin");
835+
let project_dir = check_pants_bin_name_chroot.path().join("project");
836+
let existing_path =
837+
env::split_paths(&env::var_os("PATH").unwrap_or("".into())).collect::<Vec<_>>();
838+
let path = env::join_paths(
839+
[bin_dir.as_os_str()]
840+
.into_iter()
841+
.chain(existing_path.iter().map(|p| p.as_os_str())),
842+
)
843+
.unwrap();
844+
ensure_directory(&bin_dir, true)?;
845+
846+
ensure_directory(&project_dir, true)?;
847+
write_file(
848+
&project_dir.join("pants.toml"),
849+
false,
850+
r#"
851+
[GLOBAL]
852+
pants_version = "2.14.1"
853+
# TODO(John Sirois): This works around ongoing issues with pantsd termination
854+
# variously crashing or hanging depending on Pants version.
855+
pantsd = false
856+
[anonymous-telemetry]
857+
enabled = false
858+
"#,
859+
)?;
860+
861+
softlink(scie_pants_scie, &bin_dir.join("foo"))?;
862+
softlink(scie_pants_scie, &project_dir.join("bar"))?;
863+
let absolute_argv0_path = check_pants_bin_name_chroot.path().join("baz");
864+
softlink(scie_pants_scie, &absolute_argv0_path)?;
865+
866+
let assert_pants_bin_name =
867+
|argv0: &str, expected_bin_name: &str, extra_envs: Vec<(_, _)>| -> ExitResult {
868+
let output = String::from_utf8(
869+
execute(
870+
Command::new(argv0)
871+
.arg("help-advanced")
872+
.arg("global")
873+
.env("PATH", &path)
874+
.envs(extra_envs)
875+
.current_dir(&project_dir)
876+
.stdout(Stdio::piped()),
877+
)?
878+
.stdout,
879+
)
880+
.unwrap();
881+
let expected_output =
882+
format!("current value: {expected_bin_name} (from env var PANTS_BIN_NAME)");
883+
assert!(
884+
output.contains(&expected_output),
885+
"Expected:{EOL}{expected_output}{EOL}STDOUT was:{EOL}{output}"
886+
);
887+
Ok(())
888+
};
889+
890+
assert_pants_bin_name("foo", "foo", vec![])?;
891+
assert_pants_bin_name("./bar", "./bar", vec![])?;
892+
893+
let absolute_argv0 = absolute_argv0_path.to_str().unwrap();
894+
assert_pants_bin_name(absolute_argv0, absolute_argv0, vec![])?;
895+
assert_pants_bin_name(absolute_argv0, "spam", vec![("PANTS_BIN_NAME", "spam")])?;
896+
}
897+
830898
integration_test!("Checking .pants.bootstrap handling ignores bash functions");
831899
// N.B.: We run this test after 1st having run the test above to ensure pants is already
832900
// bootstrapped so that we don't get stderr output from that process. We also use

src/main.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,13 @@ fn get_pants_process() -> Result<Process> {
213213
}
214214
};
215215

216+
let pants_bin_name = env::var_os("PANTS_BIN_NAME")
217+
.or_else(|| env::var_os("SCIE_ARGV0"))
218+
.unwrap_or_else(|| scie.clone().into());
219+
216220
let mut env = vec![
217221
("SCIE_BOOT".into(), scie_boot.env_value()),
218-
("PANTS_BIN_NAME".into(), scie.clone().into()),
222+
("PANTS_BIN_NAME".into(), pants_bin_name),
219223
(
220224
"PANTS_DEBUG".into(),
221225
if pants_debug { "1" } else { "" }.into(),

0 commit comments

Comments
 (0)