From c63d41a30af9a468324c85afa74d4eb3c1747de9 Mon Sep 17 00:00:00 2001 From: messense Date: Tue, 17 Aug 2021 15:40:17 +0800 Subject: [PATCH] Skip unavailable Python interpreters from pyenv --- src/python_interpreter.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/python_interpreter.rs b/src/python_interpreter.rs index 1aedb35e6..d54a911c6 100644 --- a/src/python_interpreter.rs +++ b/src/python_interpreter.rs @@ -7,7 +7,7 @@ use std::collections::HashSet; use std::fmt; use std::io; use std::path::{Path, PathBuf}; -use std::process::{Command, Stdio}; +use std::process::Command; use std::str; /// This snippets will give us information about the python interpreter's @@ -414,7 +414,6 @@ impl PythonInterpreter { ) -> Result> { let output = Command::new(&executable.as_ref()) .args(&["-c", GET_INTERPRETER_METADATA]) - .stderr(Stdio::inherit()) .output(); let err_msg = format!( @@ -426,7 +425,20 @@ impl PythonInterpreter { if output.status.success() { output } else { - bail!(err_msg); + let stderr = str::from_utf8(&output.stderr).unwrap(); + if stderr.starts_with(&format!( + "pyenv: {}: command not found", + executable.as_ref().display() + )) { + eprintln!( + "⚠️ Warning: skipped unavailable python interpreter '{}' from pyenv", + executable.as_ref().display() + ); + return Ok(None); + } else { + eprintln!("{}", stderr); + bail!(err_msg); + } } } Err(err) => {