Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions crates/pet-reporter/src/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ pub struct StdioReporter {
print_list: bool,
managers: Arc<Mutex<HashMap<EnvManagerType, u16>>>,
environments: Arc<Mutex<HashMap<Option<PythonEnvironmentKind>, u16>>>,
environment_paths: Arc<Mutex<HashMap<Option<PythonEnvironmentKind>, Vec<PythonEnvironment>>>>,
kind: Option<PythonEnvironmentKind>,
}

pub struct Summary {
pub managers: HashMap<EnvManagerType, u16>,
pub environments: HashMap<Option<PythonEnvironmentKind>, u16>,
pub environment_paths: HashMap<Option<PythonEnvironmentKind>, Vec<PythonEnvironment>>,
}

impl StdioReporter {
Expand All @@ -33,9 +35,14 @@ impl StdioReporter {
.environments
.lock()
.expect("environments mutex poisoned");
let environment_paths = self
.environment_paths
.lock()
.expect("environment_paths mutex poisoned");
Summary {
managers: managers.clone(),
environments: environments.clone(),
environment_paths: environment_paths.clone(),
}
}
}
Expand All @@ -62,6 +69,15 @@ impl Reporter for StdioReporter {
.expect("environments mutex poisoned");
let count = environments.get(&env.kind).unwrap_or(&0) + 1;
environments.insert(env.kind, count);

// Store the environment details for verbose reporting
let mut environment_paths = self
.environment_paths
.lock()
.expect("environment_paths mutex poisoned");
let paths = environment_paths.entry(env.kind).or_default();
paths.push(env.clone());

if self.print_list {
println!("{env}")
}
Expand All @@ -73,6 +89,7 @@ pub fn create_reporter(print_list: bool, kind: Option<PythonEnvironmentKind>) ->
print_list,
managers: Arc::new(Mutex::new(HashMap::new())),
environments: Arc::new(Mutex::new(HashMap::new())),
environment_paths: Arc::new(Mutex::new(HashMap::new())),
kind,
}
}
Expand Down
24 changes: 22 additions & 2 deletions crates/pet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,16 @@ pub fn initialize_tracing(verbose: bool) {
if use_json {
tracing_subscriber::registry()
.with(filter)
.with(fmt::layer().json())
.with(fmt::layer().json().with_writer(std::io::stderr))
.init();
} else {
tracing_subscriber::registry()
.with(filter)
.with(
fmt::layer()
.with_target(true)
.with_timer(fmt::time::uptime()),
.with_timer(fmt::time::uptime())
.with_writer(std::io::stderr),
)
.init();
}
Expand Down Expand Up @@ -196,6 +197,25 @@ fn find_envs(
}

let summary = stdio_reporter.get_summary();

// If verbose, print the paths of discovered environments first
if options.verbose && !summary.environment_paths.is_empty() {
println!("Environment Paths:");
println!("------------------");
for (kind, envs) in summary.environment_paths.iter() {
let kind_str = kind
.map(|v| format!("{v:?}"))
.unwrap_or("Unknown".to_string());
println!("\n{kind_str}:");
for env in envs {
if let Some(executable) = &env.executable {
println!(" - {}", executable.display());
}
}
}
println!()
}

if !summary.managers.is_empty() {
println!("Managers:");
println!("---------");
Expand Down
Loading