Skip to content

Commit e360a27

Browse files
authored
Add more information about missing conda env_dirs (#99)
1 parent 9c7809e commit e360a27

File tree

2 files changed

+70
-37
lines changed

2 files changed

+70
-37
lines changed

crates/pet-conda/src/telemetry.rs

Lines changed: 66 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
use std::{collections::HashSet, path::PathBuf};
4+
use std::{collections::HashSet, path::PathBuf, vec};
55

66
use log::warn;
77
use pet_core::{
@@ -23,7 +23,8 @@ pub fn report_missing_envs(
2323
conda_info: &CondaInfo,
2424
user_provided_conda_exe: bool,
2525
) -> Option<()> {
26-
let missing_envs = log_and_find_missing_envs(possibly_missing_envs, known_envs, conda_info)?;
26+
let missing_envs = log_and_find_missing_envs(possibly_missing_envs, known_envs, conda_info)
27+
.unwrap_or_default();
2728
let known_conda_rcs = get_all_known_conda_rc(env_vars, known_envs);
2829
let conda_manager_not_found = !known_envs
2930
.iter()
@@ -34,11 +35,13 @@ pub fn report_missing_envs(
3435
.collect();
3536
let mut discovered_env_dirs: HashSet<_> = known_conda_rcs
3637
.iter()
37-
.flat_map(|rc| rc.env_dirs.iter())
38+
.flat_map(|rc| rc.env_dirs.clone().into_iter())
3839
.collect();
3940
let known_env_prefixes: HashSet<_> =
4041
known_envs.iter().filter_map(|e| e.prefix.clone()).collect();
4142

43+
let mut conda_env_dirs = vec![];
44+
4245
let mut root_prefix_not_found = false;
4346
let mut conda_prefix_not_found = false;
4447
if let Some(prefix) = conda_info.root_prefix.as_ref() {
@@ -54,43 +57,66 @@ pub fn report_missing_envs(
5457
}
5558
}
5659

57-
let (sys_conda_rc_not_found, missing_from_sys_rc_env_dirs, missing_env_dirs_from_sys_rc) =
58-
count_missing_envs(
59-
&mut discovered_conda_rcs,
60-
&mut discovered_env_dirs,
61-
&missing_envs,
62-
&conda_info
63-
.sys_rc_path
64-
.clone()
65-
.map(|x| [x])
66-
.unwrap_or_default(),
67-
"sys",
68-
);
60+
let (
61+
sys_conda_rc_not_found,
62+
missing_from_sys_rc_env_dirs,
63+
missing_env_dirs_from_sys_rc,
64+
mut env_dirs,
65+
) = count_missing_envs(
66+
&mut discovered_conda_rcs,
67+
&mut discovered_env_dirs,
68+
&missing_envs,
69+
&conda_info
70+
.sys_rc_path
71+
.clone()
72+
.map(|x| [x])
73+
.unwrap_or_default(),
74+
"sys",
75+
);
76+
conda_env_dirs.append(&mut env_dirs);
77+
78+
let (
79+
user_conda_rc_not_found,
80+
missing_from_user_rc_env_dirs,
81+
missing_env_dirs_from_user_rc,
82+
mut env_dirs,
83+
) = count_missing_envs(
84+
&mut discovered_conda_rcs,
85+
&mut discovered_env_dirs,
86+
&missing_envs,
87+
&conda_info
88+
.user_rc_path
89+
.clone()
90+
.map(|x| [x])
91+
.unwrap_or_default(),
92+
"user",
93+
);
94+
conda_env_dirs.append(&mut env_dirs);
6995

70-
let (user_conda_rc_not_found, missing_from_user_rc_env_dirs, missing_env_dirs_from_user_rc) =
71-
count_missing_envs(
72-
&mut discovered_conda_rcs,
73-
&mut discovered_env_dirs,
74-
&missing_envs,
75-
&conda_info
76-
.user_rc_path
77-
.clone()
78-
.map(|x| [x])
79-
.unwrap_or_default(),
80-
"user",
81-
);
96+
let (
97+
other_conda_rc_not_found,
98+
missing_from_other_rc_env_dirs,
99+
missing_env_dirs_from_other_rc,
100+
mut env_dirs,
101+
) = count_missing_envs(
102+
&mut discovered_conda_rcs,
103+
&mut discovered_env_dirs,
104+
&missing_envs,
105+
&conda_info.config_files,
106+
"other",
107+
);
108+
conda_env_dirs.append(&mut env_dirs);
82109

83-
let (other_conda_rc_not_found, missing_from_other_rc_env_dirs, missing_env_dirs_from_other_rc) =
84-
count_missing_envs(
85-
&mut discovered_conda_rcs,
86-
&mut discovered_env_dirs,
87-
&missing_envs,
88-
&conda_info.config_files,
89-
"other",
90-
);
110+
let conda_env_dirs: HashSet<_> = conda_env_dirs.into_iter().collect();
111+
let missing_conda_env_dirs = conda_env_dirs.difference(&discovered_env_dirs).count();
91112

92113
let missing_info = MissingCondaEnvironments {
93114
missing: missing_envs.len() as u16,
115+
env_dirs_not_found: if missing_conda_env_dirs > 0 {
116+
Some(missing_conda_env_dirs as u16)
117+
} else {
118+
None
119+
},
94120
user_provided_conda_exe: if user_provided_conda_exe {
95121
Some(true)
96122
} else {
@@ -225,14 +251,15 @@ fn get_all_known_conda_rc(
225251

226252
fn count_missing_envs(
227253
discovered_conda_rcs: &mut HashSet<PathBuf>,
228-
discovered_env_dirs: &mut HashSet<&PathBuf>,
254+
discovered_env_dirs: &mut HashSet<PathBuf>,
229255
missing_envs: &[PathBuf],
230256
config_files: &[PathBuf],
231257
config_type: &str,
232-
) -> (u16, u16, u16) {
258+
) -> (u16, u16, u16, Vec<PathBuf>) {
233259
let mut conda_rc_not_found = 0;
234260
let mut missing_from_rc_env_dirs = 0;
235261
let mut missing_env_dirs_from_rc = 0;
262+
let mut env_dirs = vec![];
236263

237264
for rc in config_files.iter() {
238265
// We are not interested in the rc if it does not exist.
@@ -247,6 +274,7 @@ fn count_missing_envs(
247274

248275
if let Some(cfg) = Condarc::from_path(rc) {
249276
for env_dir in cfg.env_dirs.iter().filter(|d| d.exists()) {
277+
env_dirs.push(env_dir.clone());
250278
if !discovered_env_dirs.contains(env_dir) {
251279
missing_env_dirs_from_rc += 1;
252280
warn!(
@@ -272,5 +300,6 @@ fn count_missing_envs(
272300
conda_rc_not_found,
273301
missing_from_rc_env_dirs,
274302
missing_env_dirs_from_rc,
303+
env_dirs,
275304
)
276305
}

crates/pet-core/src/telemetry/missing_conda_info.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ use serde::{Deserialize, Serialize};
1212
pub struct MissingCondaEnvironments {
1313
/// Total number of missing conda envs.
1414
pub missing: u16,
15+
/// Total number of env_dirs not found even after parsing the conda_rc files.
16+
/// This will tell us that we are either unable to parse some of the conda_rc files or there are other
17+
/// env_dirs that we are not able to find.
18+
pub env_dirs_not_found: Option<u16>,
1519
/// Whether the user provided a conda executable.
1620
pub user_provided_conda_exe: Option<bool>,
1721
/// Whether the root prefix returned by conda was not found by us.

0 commit comments

Comments
 (0)