Skip to content

Commit

Permalink
Skip unavailable Python interpreters from pyenv
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Aug 17, 2021
1 parent efc9dd8 commit c63d41a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/python_interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -414,7 +414,6 @@ impl PythonInterpreter {
) -> Result<Option<PythonInterpreter>> {
let output = Command::new(&executable.as_ref())
.args(&["-c", GET_INTERPRETER_METADATA])
.stderr(Stdio::inherit())
.output();

let err_msg = format!(
Expand All @@ -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) => {
Expand Down

0 comments on commit c63d41a

Please # to comment.