|
1 | 1 | use crate::prelude::*; |
2 | 2 | use std::{path::PathBuf, process::Command}; |
3 | 3 |
|
| 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 | + |
4 | 38 | fn find_uv_python_paths() -> anyhow::Result<Vec<String>> { |
5 | 39 | let output = Command::new("uv") |
6 | 40 | .args([ |
@@ -53,10 +87,15 @@ fn find_system_python_paths() -> anyhow::Result<Vec<String>> { |
53 | 87 |
|
54 | 88 | fn find_python_paths() -> anyhow::Result<Vec<String>> { |
55 | 89 | let uv_paths = find_uv_python_paths().unwrap_or_default(); |
| 90 | + debug!("uv python paths: {uv_paths:?}"); |
56 | 91 | 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:?}"); |
57 | 95 |
|
58 | 96 | let mut paths = uv_paths; |
59 | 97 | paths.extend(system_paths); |
| 98 | + paths.extend(venv_paths); |
60 | 99 | paths.sort(); |
61 | 100 | paths.dedup(); |
62 | 101 | Ok(paths) |
@@ -143,6 +182,7 @@ pub fn get_objects_path_to_ignore() -> Vec<String> { |
143 | 182 |
|
144 | 183 | objects_path_to_ignore.sort(); |
145 | 184 | objects_path_to_ignore.dedup(); |
| 185 | + debug!("Final objects_path_to_ignore: {objects_path_to_ignore:#?}"); |
146 | 186 |
|
147 | 187 | objects_path_to_ignore |
148 | 188 | } |
0 commit comments