Skip to content

Commit 4b73208

Browse files
authored
Fix compilation error and use PathBuf::from (#23339)
1 parent d619a45 commit 4b73208

File tree

3 files changed

+36
-49
lines changed

3 files changed

+36
-49
lines changed

native_locator/src/common_python.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,16 @@ fn report_path_python(path: &str) {
3434
}
3535

3636
fn report_python_on_path() {
37-
let paths = env::var("PATH");
3837
let bin = if cfg!(windows) {
3938
"python.exe"
4039
} else {
4140
"python"
4241
};
43-
match paths {
44-
Ok(paths) => {
45-
let paths = env::split_paths(&paths);
46-
for path in paths {
47-
let full_path = path.join(bin);
48-
if full_path.exists() {
49-
match full_path.to_str() {
50-
Some(full_path) => report_path_python(full_path),
51-
None => (),
52-
}
53-
}
54-
}
55-
}
56-
Err(_) => (),
42+
if let Ok(paths) = env::var("PATH") {
43+
env::split_paths(&paths)
44+
.map(|p| p.join(bin))
45+
.filter(|p| p.exists())
46+
.for_each(|full_path| report_path_python(full_path.to_str().unwrap()));
5747
}
5848
}
5949

native_locator/src/conda.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -183,24 +183,24 @@ fn get_known_conda_locations() -> Vec<PathBuf> {
183183
#[cfg(unix)]
184184
fn get_known_conda_locations() -> Vec<PathBuf> {
185185
let mut known_paths = vec![
186-
Path::new("/opt/anaconda3/bin").to_path_buf(),
187-
Path::new("/opt/miniconda3/bin").to_path_buf(),
188-
Path::new("/usr/local/anaconda3/bin").to_path_buf(),
189-
Path::new("/usr/local/miniconda3/bin").to_path_buf(),
190-
Path::new("/usr/anaconda3/bin").to_path_buf(),
191-
Path::new("/usr/miniconda3/bin").to_path_buf(),
192-
Path::new("/home/anaconda3/bin").to_path_buf(),
193-
Path::new("/home/miniconda3/bin").to_path_buf(),
194-
Path::new("/anaconda3/bin").to_path_buf(),
195-
Path::new("/miniconda3/bin").to_path_buf(),
196-
Path::new("/usr/local/anaconda3/bin").to_path_buf(),
197-
Path::new("/usr/local/miniconda3/bin").to_path_buf(),
198-
Path::new("/usr/anaconda3/bin").to_path_buf(),
199-
Path::new("/usr/miniconda3/bin").to_path_buf(),
200-
Path::new("/home/anaconda3/bin").to_path_buf(),
201-
Path::new("/home/miniconda3/bin").to_path_buf(),
202-
Path::new("/anaconda3/bin").to_path_buf(),
203-
Path::new("/miniconda3/bin").to_path_buf(),
186+
PathBuf::from("/opt/anaconda3/bin"),
187+
PathBuf::from("/opt/miniconda3/bin"),
188+
PathBuf::from("/usr/local/anaconda3/bin"),
189+
PathBuf::from("/usr/local/miniconda3/bin"),
190+
PathBuf::from("/usr/anaconda3/bin"),
191+
PathBuf::from("/usr/miniconda3/bin"),
192+
PathBuf::from("/home/anaconda3/bin"),
193+
PathBuf::from("/home/miniconda3/bin"),
194+
PathBuf::from("/anaconda3/bin"),
195+
PathBuf::from("/miniconda3/bin"),
196+
PathBuf::from("/usr/local/anaconda3/bin"),
197+
PathBuf::from("/usr/local/miniconda3/bin"),
198+
PathBuf::from("/usr/anaconda3/bin"),
199+
PathBuf::from("/usr/miniconda3/bin"),
200+
PathBuf::from("/home/anaconda3/bin"),
201+
PathBuf::from("/home/miniconda3/bin"),
202+
PathBuf::from("/anaconda3/bin"),
203+
PathBuf::from("/miniconda3/bin"),
204204
];
205205
known_paths.append(&mut known::get_know_global_search_locations());
206206
known_paths
@@ -333,7 +333,7 @@ fn get_distinct_conda_envs(conda_bin: PathBuf) -> Vec<CondaEnv> {
333333

334334
let locations = get_known_env_locations(conda_bin);
335335
let mut conda_envs = vec![];
336-
for env in envs.clone() {
336+
for env in envs {
337337
let env = Path::new(&env);
338338
let mut named = false;
339339
let mut name = "".to_string();

native_locator/src/known.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT License.
33
use std::{env, path::PathBuf};
44

5-
65
#[cfg(windows)]
76
pub fn get_know_global_search_locations() -> Vec<PathBuf> {
87
vec![]
@@ -11,23 +10,21 @@ pub fn get_know_global_search_locations() -> Vec<PathBuf> {
1110
#[cfg(unix)]
1211
pub fn get_know_global_search_locations() -> Vec<PathBuf> {
1312
vec![
14-
Path::new("/usr/bin").to_path_buf(),
15-
Path::new("/usr/local/bin").to_path_buf(),
16-
Path::new("/bin").to_path_buf(),
17-
Path::new("/home/bin").to_path_buf(),
18-
Path::new("/sbin").to_path_buf(),
19-
Path::new("/usr/sbin").to_path_buf(),
20-
Path::new("/usr/local/sbin").to_path_buf(),
21-
Path::new("/home/sbin").to_path_buf(),
22-
Path::new("/opt").to_path_buf(),
23-
Path::new("/opt/bin").to_path_buf(),
24-
Path::new("/opt/sbin").to_path_buf(),
25-
Path::new("/opt/homebrew/bin").to_path_buf(),
13+
PathBuf::from("/usr/bin"),
14+
PathBuf::from("/usr/local/bin"),
15+
PathBuf::from("/bin"),
16+
PathBuf::from("/home/bin"),
17+
PathBuf::from("/sbin"),
18+
PathBuf::from("/usr/sbin"),
19+
PathBuf::from("/usr/local/sbin"),
20+
PathBuf::from("/home/sbin"),
21+
PathBuf::from("/opt"),
22+
PathBuf::from("/opt/bin"),
23+
PathBuf::from("/opt/sbin"),
24+
PathBuf::from("/opt/homebrew/bin"),
2625
]
2726
}
2827

29-
30-
3128
pub fn get_user_home() -> Option<String> {
3229
let home = env::var("HOME").or_else(|_| env::var("USERPROFILE"));
3330
match home {

0 commit comments

Comments
 (0)