(
interpreter_path: impl AsRef<Path>,
search_term: &str,
)
| 40 | } |
| 41 | |
| 42 | pub fn get_python_doc( |
| 43 | interpreter_path: impl AsRef<Path>, |
| 44 | search_term: &str, |
| 45 | ) -> anyhow::Result<Option<String>> { |
| 46 | let output = Command::new(interpreter_path.as_ref()) |
| 47 | .args([ |
| 48 | "-c", |
| 49 | [ |
| 50 | "import pydoc", |
| 51 | "pydoc.pager=pydoc.plainpager", |
| 52 | &format!("pydoc.help('{search_term}')"), |
| 53 | ] |
| 54 | .join(";") |
| 55 | .as_str(), |
| 56 | ]) |
| 57 | .stdout(Stdio::piped()) |
| 58 | .output() |
| 59 | .map_err(|e| anyhow::anyhow!("Failed to get python documentation! {e}"))?; |
| 60 | |
| 61 | let output_str = String::from_utf8_lossy(&output.stdout); |
| 62 | if output_str.starts_with("No Python documentation found for") { |
| 63 | Ok(None) |
| 64 | } else { |
| 65 | Ok(Some( |
| 66 | // Skip the line with "Help on ..." |
| 67 | output_str.lines().skip(1).collect::<Vec<&str>>().join("\n"), |
| 68 | )) |
| 69 | } |
| 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()) |
no test coverage detected