Skip to content

Commit e24de7c

Browse files
committed
add environment path verbose output for discovered environments
1 parent fececfa commit e24de7c

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

crates/pet-reporter/src/stdio.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ pub struct StdioReporter {
1818
print_list: bool,
1919
managers: Arc<Mutex<HashMap<EnvManagerType, u16>>>,
2020
environments: Arc<Mutex<HashMap<Option<PythonEnvironmentKind>, u16>>>,
21+
environment_paths: Arc<Mutex<HashMap<Option<PythonEnvironmentKind>, Vec<PythonEnvironment>>>>,
2122
kind: Option<PythonEnvironmentKind>,
2223
}
2324

2425
pub struct Summary {
2526
pub managers: HashMap<EnvManagerType, u16>,
2627
pub environments: HashMap<Option<PythonEnvironmentKind>, u16>,
28+
pub environment_paths: HashMap<Option<PythonEnvironmentKind>, Vec<PythonEnvironment>>,
2729
}
2830

2931
impl StdioReporter {
@@ -33,9 +35,14 @@ impl StdioReporter {
3335
.environments
3436
.lock()
3537
.expect("environments mutex poisoned");
38+
let environment_paths = self
39+
.environment_paths
40+
.lock()
41+
.expect("environment_paths mutex poisoned");
3642
Summary {
3743
managers: managers.clone(),
3844
environments: environments.clone(),
45+
environment_paths: environment_paths.clone(),
3946
}
4047
}
4148
}
@@ -62,6 +69,15 @@ impl Reporter for StdioReporter {
6269
.expect("environments mutex poisoned");
6370
let count = environments.get(&env.kind).unwrap_or(&0) + 1;
6471
environments.insert(env.kind, count);
72+
73+
// Store the environment details for verbose reporting
74+
let mut environment_paths = self
75+
.environment_paths
76+
.lock()
77+
.expect("environment_paths mutex poisoned");
78+
let paths = environment_paths.entry(env.kind).or_insert_with(Vec::new);
79+
paths.push(env.clone());
80+
6581
if self.print_list {
6682
println!("{env}")
6783
}
@@ -73,6 +89,7 @@ pub fn create_reporter(print_list: bool, kind: Option<PythonEnvironmentKind>) ->
7389
print_list,
7490
managers: Arc::new(Mutex::new(HashMap::new())),
7591
environments: Arc::new(Mutex::new(HashMap::new())),
92+
environment_paths: Arc::new(Mutex::new(HashMap::new())),
7693
kind,
7794
}
7895
}

crates/pet/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,26 @@ fn find_envs(
197197
}
198198

199199
let summary = stdio_reporter.get_summary();
200+
201+
// If verbose, print the paths of discovered environments first
202+
if options.verbose && !summary.environment_paths.is_empty() {
203+
println!("Environment Paths:");
204+
println!("------------------");
205+
for (kind, envs) in summary
206+
.environment_paths
207+
.iter()
208+
{
209+
let kind_str = kind.map(|v| format!("{v:?}")).unwrap_or("Unknown".to_string());
210+
println!("\n{kind_str}:");
211+
for env in envs {
212+
if let Some(executable) = &env.executable {
213+
println!(" - {}", executable.display());
214+
}
215+
}
216+
}
217+
println!()
218+
}
219+
200220
if !summary.managers.is_empty() {
201221
println!("Managers:");
202222
println!("---------");

0 commit comments

Comments
 (0)