1
1
// Copyright (c) Microsoft Corporation.
2
2
// Licensed under the MIT License.
3
3
4
- use std:: { collections:: HashSet , path:: PathBuf } ;
4
+ use std:: { collections:: HashSet , path:: PathBuf , vec } ;
5
5
6
6
use log:: warn;
7
7
use pet_core:: {
@@ -23,7 +23,8 @@ pub fn report_missing_envs(
23
23
conda_info : & CondaInfo ,
24
24
user_provided_conda_exe : bool ,
25
25
) -> 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 ( ) ;
27
28
let known_conda_rcs = get_all_known_conda_rc ( env_vars, known_envs) ;
28
29
let conda_manager_not_found = !known_envs
29
30
. iter ( )
@@ -34,11 +35,13 @@ pub fn report_missing_envs(
34
35
. collect ( ) ;
35
36
let mut discovered_env_dirs: HashSet < _ > = known_conda_rcs
36
37
. iter ( )
37
- . flat_map ( |rc| rc. env_dirs . iter ( ) )
38
+ . flat_map ( |rc| rc. env_dirs . clone ( ) . into_iter ( ) )
38
39
. collect ( ) ;
39
40
let known_env_prefixes: HashSet < _ > =
40
41
known_envs. iter ( ) . filter_map ( |e| e. prefix . clone ( ) ) . collect ( ) ;
41
42
43
+ let mut conda_env_dirs = vec ! [ ] ;
44
+
42
45
let mut root_prefix_not_found = false ;
43
46
let mut conda_prefix_not_found = false ;
44
47
if let Some ( prefix) = conda_info. root_prefix . as_ref ( ) {
@@ -54,43 +57,66 @@ pub fn report_missing_envs(
54
57
}
55
58
}
56
59
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) ;
69
95
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) ;
82
109
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 ( ) ;
91
112
92
113
let missing_info = MissingCondaEnvironments {
93
114
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
+ } ,
94
120
user_provided_conda_exe : if user_provided_conda_exe {
95
121
Some ( true )
96
122
} else {
@@ -225,14 +251,15 @@ fn get_all_known_conda_rc(
225
251
226
252
fn count_missing_envs (
227
253
discovered_conda_rcs : & mut HashSet < PathBuf > ,
228
- discovered_env_dirs : & mut HashSet < & PathBuf > ,
254
+ discovered_env_dirs : & mut HashSet < PathBuf > ,
229
255
missing_envs : & [ PathBuf ] ,
230
256
config_files : & [ PathBuf ] ,
231
257
config_type : & str ,
232
- ) -> ( u16 , u16 , u16 ) {
258
+ ) -> ( u16 , u16 , u16 , Vec < PathBuf > ) {
233
259
let mut conda_rc_not_found = 0 ;
234
260
let mut missing_from_rc_env_dirs = 0 ;
235
261
let mut missing_env_dirs_from_rc = 0 ;
262
+ let mut env_dirs = vec ! [ ] ;
236
263
237
264
for rc in config_files. iter ( ) {
238
265
// We are not interested in the rc if it does not exist.
@@ -247,6 +274,7 @@ fn count_missing_envs(
247
274
248
275
if let Some ( cfg) = Condarc :: from_path ( rc) {
249
276
for env_dir in cfg. env_dirs . iter ( ) . filter ( |d| d. exists ( ) ) {
277
+ env_dirs. push ( env_dir. clone ( ) ) ;
250
278
if !discovered_env_dirs. contains ( env_dir) {
251
279
missing_env_dirs_from_rc += 1 ;
252
280
warn ! (
@@ -272,5 +300,6 @@ fn count_missing_envs(
272
300
conda_rc_not_found,
273
301
missing_from_rc_env_dirs,
274
302
missing_env_dirs_from_rc,
303
+ env_dirs,
275
304
)
276
305
}
0 commit comments