From 289485d1ca08a263f3a2c064bb6e17062cc1671f Mon Sep 17 00:00:00 2001 From: Vyacheslav Bespalov Date: Fri, 26 May 2023 17:35:43 +0300 Subject: [PATCH 1/3] feature = "pythonw" --- Cargo.toml | 3 +++ src/main.rs | 16 +++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d4302e9..dbe23fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,9 @@ name = "pyenv-py" version = "0.2.2" edition = "2021" +[features] +pythonw = [] + [[bin]] name = "py" path = "src/main.rs" diff --git a/src/main.rs b/src/main.rs index e4ad1a0..aaba29d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -180,13 +180,19 @@ fn main() { .position(|v| v.components().nth_back(1).unwrap().as_os_str() != "versions"), }; - let python_binary = match version_idx_opt { + let target_name = if cfg!(feature = "pythonw") { + "pythonw" + } else { + "python" + }; + + let target_binary = match version_idx_opt { Some(version_idx) => find_binary_on_paths( - "python", + target_name, vec![py_bin_locs[version_idx].to_owned()].into_iter(), ) .unwrap_or_else(|| { - eprintln!("Unable to find python binary"); + eprintln!("Unable to find '{}' binary", target_name); process::exit(1); }), @@ -198,10 +204,10 @@ fn main() { ctrlc::set_handler(move || {}).expect("Unable to set Ctrl-C handler"); - let status = Command::new(python_binary) + let status = Command::new(target_binary) .args(py_call_args) .status() - .expect("Unable to execute the binary"); + .expect("Unable to execute '{}' binary", target_name); exit_with_child_status(status); } From 47512e6c79961f370f89213a46f97b549074d9fe Mon Sep 17 00:00:00 2001 From: Vyacheslav Bespalov Date: Fri, 26 May 2023 17:58:12 +0300 Subject: [PATCH 2/3] Fix --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index aaba29d..292926e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -207,7 +207,7 @@ fn main() { let status = Command::new(target_binary) .args(py_call_args) .status() - .expect("Unable to execute '{}' binary", target_name); + .unwrap_or_else(|_| panic!("Unable to execute '{}' binary", target_name)); exit_with_child_status(status); } From fe87b958cb0d650c42e2430e5eb6c3f019e63ab0 Mon Sep 17 00:00:00 2001 From: Vyacheslav Bespalov Date: Fri, 26 May 2023 18:04:21 +0300 Subject: [PATCH 3/3] Rename variables --- src/main.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 292926e..6a8cad5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -180,19 +180,19 @@ fn main() { .position(|v| v.components().nth_back(1).unwrap().as_os_str() != "versions"), }; - let target_name = if cfg!(feature = "pythonw") { + let binary_name = if cfg!(feature = "pythonw") { "pythonw" } else { "python" }; - let target_binary = match version_idx_opt { + let binary_path = match version_idx_opt { Some(version_idx) => find_binary_on_paths( - target_name, + binary_name, vec![py_bin_locs[version_idx].to_owned()].into_iter(), ) .unwrap_or_else(|| { - eprintln!("Unable to find '{}' binary", target_name); + eprintln!("Unable to find '{}' binary", binary_name); process::exit(1); }), @@ -204,10 +204,10 @@ fn main() { ctrlc::set_handler(move || {}).expect("Unable to set Ctrl-C handler"); - let status = Command::new(target_binary) + let status = Command::new(binary_path) .args(py_call_args) .status() - .unwrap_or_else(|_| panic!("Unable to execute '{}' binary", target_name)); + .unwrap_or_else(|_| panic!("Unable to execute '{}' binary", binary_name)); exit_with_child_status(status); }