Skip to content

Commit 14e8ae7

Browse files
committed
chore: detect venv python
1 parent 9d77cd4 commit 14e8ae7

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

src/run/runner/valgrind/helpers/ignored_objects_path.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,40 @@
11
use crate::prelude::*;
22
use std::{path::PathBuf, process::Command};
33

4+
fn find_venv_python_paths() -> anyhow::Result<Vec<String>> {
5+
let venv_path = std::env::var("VIRTUAL_ENV").ok();
6+
if venv_path.is_none() {
7+
return Ok(vec![]);
8+
}
9+
let venv_path = venv_path.unwrap();
10+
let python_path = PathBuf::from(venv_path).join("bin").join("python");
11+
if !python_path.exists() {
12+
return Ok(vec![]);
13+
}
14+
debug!("Found venv python path: {}", python_path.to_string_lossy());
15+
16+
// 'uv python find'
17+
let output = Command::new("uv")
18+
.args(["python", "find", &python_path.to_string_lossy()])
19+
.output()?;
20+
if !output.status.success() {
21+
bail!(
22+
"Failed to get venv python path: {}",
23+
String::from_utf8_lossy(&output.stderr)
24+
);
25+
}
26+
let python_path = PathBuf::from(String::from_utf8_lossy(&output.stdout).trim());
27+
if !python_path.exists() {
28+
return Ok(vec![]);
29+
}
30+
debug!(
31+
"Resolved venv python path: {}",
32+
python_path.to_string_lossy()
33+
);
34+
35+
Ok(vec![python_path.to_string_lossy().to_string()])
36+
}
37+
438
fn find_uv_python_paths() -> anyhow::Result<Vec<String>> {
539
let output = Command::new("uv")
640
.args([
@@ -53,10 +87,15 @@ fn find_system_python_paths() -> anyhow::Result<Vec<String>> {
5387

5488
fn find_python_paths() -> anyhow::Result<Vec<String>> {
5589
let uv_paths = find_uv_python_paths().unwrap_or_default();
90+
debug!("uv python paths: {uv_paths:?}");
5691
let system_paths = find_system_python_paths().unwrap_or_default();
92+
debug!("system python paths: {system_paths:?}");
93+
let venv_paths = find_venv_python_paths().unwrap_or_default();
94+
debug!("venv python paths: {venv_paths:?}");
5795

5896
let mut paths = uv_paths;
5997
paths.extend(system_paths);
98+
paths.extend(venv_paths);
6099
paths.sort();
61100
paths.dedup();
62101
Ok(paths)
@@ -143,6 +182,7 @@ pub fn get_objects_path_to_ignore() -> Vec<String> {
143182

144183
objects_path_to_ignore.sort();
145184
objects_path_to_ignore.dedup();
185+
debug!("Final objects_path_to_ignore: {objects_path_to_ignore:#?}");
146186

147187
objects_path_to_ignore
148188
}

0 commit comments

Comments
 (0)