MCPcopy Create free account
hub / github.com/LaBatata101/sith-language-server / get_python_version

Function get_python_version

crates/sith_python_utils/src/lib.rs:72–86  ·  view source on GitHub ↗
(interpreter_path: impl AsRef<Path>)

Source from the content-addressed store, hash-verified

70}
71
72pub 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
88pub(crate) fn parse_python_version(version_str: &str) -> anyhow::Result<PythonVersion> {
89 let version_segments = version_str.split(".").collect::<Vec<_>>();

Callers 1

newMethod · 0.85

Calls 3

parse_python_versionFunction · 0.85
as_refMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected