Merge pull request #620 from namuyan/master

check python interpreter by --version option
This commit is contained in:
Yuji Kanagawa 2019-10-12 17:39:49 +09:00 committed by GitHub
commit 77f8cad65f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 4 deletions

View File

@ -25,11 +25,16 @@ const MIN_VERSION: &'static str = "1.37.0-nightly";
lazy_static! {
static ref PYTHON_INTERPRETER: &'static str = {
["python3", "python"]
["python", "python3"]
.iter()
.map(|bin| (bin, Command::new(bin).spawn()))
.find(|(_, r)| r.is_ok())
.map(|(bin, _)| bin)
.find(|bin| {
if let Ok(out) = Command::new(bin).arg("--version").output() {
// begin with `Python 3.X.X :: additional info`
out.stdout.starts_with(b"Python 3") || out.stderr.starts_with(b"Python 3")
} else {
false
}
})
.expect("Python 3.x interpreter not found")
};
}