@@ -6,7 +6,7 @@ use log::trace;
6
6
use pet_fs:: path:: expand_path;
7
7
use std:: {
8
8
collections:: HashSet ,
9
- fs,
9
+ env , fs,
10
10
path:: { Path , PathBuf } ,
11
11
} ;
12
12
use yaml_rust2:: YamlLoader ;
@@ -29,7 +29,7 @@ impl Condarc {
29
29
// Search paths documented here
30
30
// https://conda.io/projects/conda/en/latest/user-guide/configuration/use-condarc.html#searching-for-condarc
31
31
// https://github.com/conda/conda/blob/3ae5d7cf6cbe2b0ff9532359456b7244ae1ea5ef/conda/base/constants.py#L28
32
- fn get_conda_rc_search_paths ( env_vars : & EnvVariables ) -> Vec < PathBuf > {
32
+ pub fn get_conda_rc_search_paths ( env_vars : & EnvVariables ) -> Vec < PathBuf > {
33
33
use crate :: utils:: change_root_of_path;
34
34
35
35
let mut search_paths: Vec < PathBuf > = vec ! [ ] ;
@@ -40,6 +40,22 @@ fn get_conda_rc_search_paths(env_vars: &EnvVariables) -> Vec<PathBuf> {
40
40
"C:\\ ProgramData\\ conda\\ .condarc" ,
41
41
"C:\\ ProgramData\\ conda\\ condarc" ,
42
42
"C:\\ ProgramData\\ conda\\ condarc.d" ,
43
+ "C:\\ ProgramData\\ conda\\ .mambarc" ,
44
+ format ! (
45
+ "{}:\\ ProgramData\\ conda\\ .condarc" ,
46
+ env:: var( "SYSTEMDRIVE" ) . unwrap_or( "C" . to_string( ) )
47
+ )
48
+ . as_str ( ) ,
49
+ format ! (
50
+ "{}:\\ ProgramData\\ conda\\ condarc" ,
51
+ env:: var( "SYSTEMDRIVE" ) . unwrap_or( "C" . to_string( ) )
52
+ )
53
+ . as_str ( ) ,
54
+ format ! (
55
+ "{}:\\ ProgramData\\ conda\\ condarc.d" ,
56
+ env:: var( "SYSTEMDRIVE" ) . unwrap_or( "C" . to_string( ) )
57
+ )
58
+ . as_str ( ) ,
43
59
]
44
60
. iter ( )
45
61
. map ( PathBuf :: from)
@@ -51,9 +67,11 @@ fn get_conda_rc_search_paths(env_vars: &EnvVariables) -> Vec<PathBuf> {
51
67
"/etc/conda/.condarc" ,
52
68
"/etc/conda/condarc" ,
53
69
"/etc/conda/condarc.d" ,
70
+ "/etc/conda/mambarc" ,
54
71
"/var/lib/conda/.condarc" ,
55
72
"/var/lib/conda/condarc" ,
56
73
"/var/lib/conda/condarc.d" ,
74
+ "/var/lib/conda/.mambarc" ,
57
75
]
58
76
. iter ( )
59
77
. map ( PathBuf :: from)
@@ -63,17 +81,20 @@ fn get_conda_rc_search_paths(env_vars: &EnvVariables) -> Vec<PathBuf> {
63
81
) ;
64
82
}
65
83
if let Some ( ref conda_root) = env_vars. conda_root {
84
+ let conda_root = expand_path ( PathBuf :: from ( conda_root. clone ( ) ) ) ;
66
85
search_paths. append ( & mut vec ! [
67
- PathBuf :: from( conda_root. clone( ) ) . join( ".condarc" ) ,
68
- PathBuf :: from( conda_root. clone( ) ) . join( "condarc" ) ,
69
- PathBuf :: from( conda_root. clone( ) ) . join( ".condarc.d" ) ,
86
+ conda_root. join( ".condarc" ) ,
87
+ conda_root. join( "condarc" ) ,
88
+ conda_root. join( ".condarc.d" ) ,
89
+ conda_root. join( ".mambarc" ) ,
70
90
] ) ;
71
91
}
72
92
if let Some ( ref xdg_config_home) = env_vars. xdg_config_home {
73
93
search_paths. append ( & mut vec ! [
74
94
PathBuf :: from( xdg_config_home. clone( ) ) . join( ".condarc" ) ,
75
95
PathBuf :: from( xdg_config_home. clone( ) ) . join( "condarc" ) ,
76
96
PathBuf :: from( xdg_config_home. clone( ) ) . join( ".condarc.d" ) ,
97
+ PathBuf :: from( xdg_config_home. clone( ) ) . join( ".mambarc" ) ,
77
98
] ) ;
78
99
}
79
100
if let Some ( ref home) = env_vars. home {
@@ -85,24 +106,33 @@ fn get_conda_rc_search_paths(env_vars: &EnvVariables) -> Vec<PathBuf> {
85
106
home. join( ".conda" ) . join( "condarc" ) ,
86
107
home. join( ".conda" ) . join( "condarc.d" ) ,
87
108
home. join( ".condarc" ) ,
109
+ home. join( "condarc" ) ,
110
+ home. join( "condarc.d" ) ,
111
+ home. join( ".mambarc" ) ,
88
112
] ) ;
89
113
}
90
114
if let Some ( ref conda_prefix) = env_vars. conda_prefix {
115
+ let conda_prefix = expand_path ( PathBuf :: from ( conda_prefix. clone ( ) ) ) ;
91
116
search_paths. append ( & mut vec ! [
92
- PathBuf :: from( conda_prefix. clone( ) ) . join( ".condarc" ) ,
93
- PathBuf :: from( conda_prefix. clone( ) ) . join( "condarc" ) ,
94
- PathBuf :: from( conda_prefix. clone( ) ) . join( ".condarc.d" ) ,
117
+ conda_prefix. join( ".condarc" ) ,
118
+ conda_prefix. join( "condarc" ) ,
119
+ conda_prefix. join( ".condarc.d" ) ,
120
+ conda_prefix. join( ".mamabarc" ) ,
95
121
] ) ;
96
122
}
97
123
if let Some ( ref conda_dir) = env_vars. conda_dir {
124
+ let conda_dir = expand_path ( PathBuf :: from ( conda_dir. clone ( ) ) ) ;
98
125
search_paths. append ( & mut vec ! [
99
- PathBuf :: from ( conda_dir. clone ( ) ) . join( ".condarc" ) ,
100
- PathBuf :: from ( conda_dir. clone ( ) ) . join( "condarc" ) ,
101
- PathBuf :: from ( conda_dir. clone ( ) ) . join( ".condarc.d" ) ,
126
+ conda_dir. join( ".condarc" ) ,
127
+ conda_dir. join( "condarc" ) ,
128
+ conda_dir. join( ".condarc.d" ) ,
102
129
] ) ;
103
130
}
104
131
if let Some ( ref condarc) = env_vars. condarc {
105
- search_paths. append ( & mut vec ! [ PathBuf :: from( condarc) ] ) ;
132
+ search_paths. append ( & mut vec ! [ expand_path( PathBuf :: from( condarc) ) ] ) ;
133
+ }
134
+ if let Some ( ref mambarc) = env_vars. mambarc {
135
+ search_paths. append ( & mut vec ! [ expand_path( PathBuf :: from( mambarc) ) ] ) ;
106
136
}
107
137
108
138
let search_paths: HashSet < _ > = search_paths. into_iter ( ) . collect ( ) ;
@@ -157,15 +187,21 @@ fn get_conda_conda_rc_from_path(conda_rc: &PathBuf) -> Option<Condarc> {
157
187
. map ( |e| e. path ( ) )
158
188
. filter ( |p| p. is_file ( ) )
159
189
{
160
- let file_name = path. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap_or_default ( ) ;
190
+ let file_name = path
191
+ . file_name ( )
192
+ . unwrap ( )
193
+ . to_str ( )
194
+ . unwrap_or_default ( )
195
+ . to_lowercase ( ) ;
161
196
let extension = path
162
197
. extension ( )
163
198
. unwrap_or_default ( )
164
199
. to_str ( )
165
- . unwrap_or_default ( ) ;
200
+ . unwrap_or_default ( )
201
+ . to_lowercase ( ) ;
166
202
167
- if POSSIBLE_CONDA_RC_FILES . contains ( & file_name)
168
- || SUPPORTED_EXTENSIONS . contains ( & extension)
203
+ if POSSIBLE_CONDA_RC_FILES . contains ( & file_name. as_str ( ) )
204
+ || SUPPORTED_EXTENSIONS . contains ( & extension. as_str ( ) )
169
205
|| file_name. contains ( "condarc" )
170
206
{
171
207
if let Some ( ref mut cfg) = parse_conda_rc ( & path) {
@@ -186,13 +222,14 @@ fn get_conda_conda_rc_from_path(conda_rc: &PathBuf) -> Option<Condarc> {
186
222
187
223
fn parse_conda_rc ( conda_rc : & Path ) -> Option < Condarc > {
188
224
let reader = fs:: read_to_string ( conda_rc) . ok ( ) ?;
189
- trace ! ( "Possible conda_rc: {:?}" , conda_rc) ;
190
225
if let Some ( cfg) = parse_conda_rc_contents ( & reader) {
226
+ trace ! ( "conda_rc: {:?} with env_dirs {:?}" , conda_rc, cfg. env_dirs) ;
191
227
Some ( Condarc {
192
228
env_dirs : cfg. env_dirs ,
193
229
files : vec ! [ conda_rc. to_path_buf( ) ] ,
194
230
} )
195
231
} else {
232
+ trace ! ( "Failed to parse or empty conda_rc: {:?}" , conda_rc) ;
196
233
Some ( Condarc {
197
234
env_dirs : vec ! [ ] ,
198
235
files : vec ! [ conda_rc. to_path_buf( ) ] ,
@@ -220,7 +257,9 @@ fn parse_conda_rc_contents(contents: &str) -> Option<Condarc> {
220
257
if item_str. is_empty ( ) {
221
258
continue ;
222
259
}
223
- env_dirs. push ( expand_path ( PathBuf :: from ( item_str. trim ( ) ) ) ) ;
260
+ let env_dir = expand_path ( PathBuf :: from ( item_str. trim ( ) ) ) ;
261
+ trace ! ( "env_dir: {:?} parsed as {:?}" , item_str. trim( ) , env_dir) ;
262
+ env_dirs. push ( env_dir) ;
224
263
}
225
264
}
226
265
if let Some ( items) = doc[ "envs_path" ] . as_vec ( ) {
@@ -229,7 +268,9 @@ fn parse_conda_rc_contents(contents: &str) -> Option<Condarc> {
229
268
if item_str. is_empty ( ) {
230
269
continue ;
231
270
}
232
- env_dirs. push ( expand_path ( PathBuf :: from ( item_str. trim ( ) ) ) ) ;
271
+ let env_dir = expand_path ( PathBuf :: from ( item_str. trim ( ) ) ) ;
272
+ trace ! ( "env_path: {:?} parsed as {:?}" , item_str. trim( ) , env_dir) ;
273
+ env_dirs. push ( env_dir) ;
233
274
}
234
275
}
235
276
}
0 commit comments