(interpreter_path: impl AsRef<Path>)
| 70 | } |
| 71 | |
| 72 | pub fn get_python_version(interpreter_path: impl AsRef<Path>) -> anyhow::Result<PythonVersion> { |
| 73 | let output = Command::new(interpreter_path.as_ref()) |
| 74 | .arg("--version") |
| 75 | .stdout(Stdio::piped()) |
| 76 | .output() |
| 77 | .map_err(|_| anyhow::anyhow!("Failed to get python version!"))?; |
| 78 | |
| 79 | let output_str = String::from_utf8_lossy(&output.stdout); |
| 80 | let output_segments = output_str.split(" ").collect::<Vec<&str>>(); |
| 81 | let version_output = output_segments |
| 82 | .get(1) |
| 83 | .ok_or_else(|| anyhow::anyhow!("Incorrect Python version output!"))?; |
| 84 | |
| 85 | parse_python_version(version_output) |
| 86 | } |
| 87 | |
| 88 | pub(crate) fn parse_python_version(version_str: &str) -> anyhow::Result<PythonVersion> { |
| 89 | let version_segments = version_str.split(".").collect::<Vec<_>>(); |
no test coverage detected