()
| 39 | } |
| 40 | |
| 41 | fn get_python_executable() -> Result<PathBuf> { |
| 42 | let possible_executables = ["python3", "python"]; |
| 43 | for executable_name in possible_executables { |
| 44 | let res = std::process::Command::new(executable_name) |
| 45 | .arg("-c") |
| 46 | .arg("import sys; print(sys.executable)") |
| 47 | .output(); |
| 48 | match res { |
| 49 | Ok(output) => { |
| 50 | let mut path = String::from_utf8(output.stdout).into_diagnostic()?; |
| 51 | // Like calling trim but I didn't want to re-allocate the str slice |
| 52 | while path.ends_with('\n') || path.ends_with('\r') { |
| 53 | path.pop(); |
| 54 | } |
| 55 | return Ok(PathBuf::from(path)); |
| 56 | } |
| 57 | Err(e) => { |
| 58 | if e.kind() != io::ErrorKind::NotFound { |
| 59 | bail!("Unknown error when looking for python executable: {e}"); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | bail!("Failed to find Python executable."); |
| 66 | } |
| 67 | |
| 68 | fn get_typeshed_path() -> Result<PathBuf> { |
| 69 | // imagine the path is in the same directory as user ran this command |
no outgoing calls