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
20 changes: 5 additions & 15 deletions native_locator/src/common_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,16 @@ fn report_path_python(path: &str) {
}

fn report_python_on_path() {
let paths = env::var("PATH");
let bin = if cfg!(windows) {
"python.exe"
} else {
"python"
};
match paths {
Ok(paths) => {
let paths = env::split_paths(&paths);
for path in paths {
let full_path = path.join(bin);
if full_path.exists() {
match full_path.to_str() {
Some(full_path) => report_path_python(full_path),
None => (),
}
}
}
}
Err(_) => (),
if let Ok(paths) = env::var("PATH") {
env::split_paths(&paths)
.map(|p| p.join(bin))
.filter(|p| p.exists())
.for_each(|full_path| report_path_python(full_path.to_str().unwrap()));
}
}

Expand Down
38 changes: 19 additions & 19 deletions native_locator/src/conda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,24 +183,24 @@ fn get_known_conda_locations() -> Vec<PathBuf> {
#[cfg(unix)]
fn get_known_conda_locations() -> Vec<PathBuf> {
let mut known_paths = vec![
Path::new("/opt/anaconda3/bin").to_path_buf(),
Path::new("/opt/miniconda3/bin").to_path_buf(),
Path::new("/usr/local/anaconda3/bin").to_path_buf(),
Path::new("/usr/local/miniconda3/bin").to_path_buf(),
Path::new("/usr/anaconda3/bin").to_path_buf(),
Path::new("/usr/miniconda3/bin").to_path_buf(),
Path::new("/home/anaconda3/bin").to_path_buf(),
Path::new("/home/miniconda3/bin").to_path_buf(),
Path::new("/anaconda3/bin").to_path_buf(),
Path::new("/miniconda3/bin").to_path_buf(),
Path::new("/usr/local/anaconda3/bin").to_path_buf(),
Path::new("/usr/local/miniconda3/bin").to_path_buf(),
Path::new("/usr/anaconda3/bin").to_path_buf(),
Path::new("/usr/miniconda3/bin").to_path_buf(),
Path::new("/home/anaconda3/bin").to_path_buf(),
Path::new("/home/miniconda3/bin").to_path_buf(),
Path::new("/anaconda3/bin").to_path_buf(),
Path::new("/miniconda3/bin").to_path_buf(),
PathBuf::from("/opt/anaconda3/bin"),
PathBuf::from("/opt/miniconda3/bin"),
PathBuf::from("/usr/local/anaconda3/bin"),
PathBuf::from("/usr/local/miniconda3/bin"),
PathBuf::from("/usr/anaconda3/bin"),
PathBuf::from("/usr/miniconda3/bin"),
PathBuf::from("/home/anaconda3/bin"),
PathBuf::from("/home/miniconda3/bin"),
PathBuf::from("/anaconda3/bin"),
PathBuf::from("/miniconda3/bin"),
PathBuf::from("/usr/local/anaconda3/bin"),
PathBuf::from("/usr/local/miniconda3/bin"),
PathBuf::from("/usr/anaconda3/bin"),
PathBuf::from("/usr/miniconda3/bin"),
PathBuf::from("/home/anaconda3/bin"),
PathBuf::from("/home/miniconda3/bin"),
PathBuf::from("/anaconda3/bin"),
PathBuf::from("/miniconda3/bin"),
];
known_paths.append(&mut known::get_know_global_search_locations());
known_paths
Expand Down Expand Up @@ -333,7 +333,7 @@ fn get_distinct_conda_envs(conda_bin: PathBuf) -> Vec<CondaEnv> {

let locations = get_known_env_locations(conda_bin);
let mut conda_envs = vec![];
for env in envs.clone() {
for env in envs {
let env = Path::new(&env);
let mut named = false;
let mut name = "".to_string();
Expand Down
27 changes: 12 additions & 15 deletions native_locator/src/known.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License.
use std::{env, path::PathBuf};


#[cfg(windows)]
pub fn get_know_global_search_locations() -> Vec<PathBuf> {
vec![]
Expand All @@ -11,23 +10,21 @@ pub fn get_know_global_search_locations() -> Vec<PathBuf> {
#[cfg(unix)]
pub fn get_know_global_search_locations() -> Vec<PathBuf> {
vec![
Path::new("/usr/bin").to_path_buf(),
Path::new("/usr/local/bin").to_path_buf(),
Path::new("/bin").to_path_buf(),
Path::new("/home/bin").to_path_buf(),
Path::new("/sbin").to_path_buf(),
Path::new("/usr/sbin").to_path_buf(),
Path::new("/usr/local/sbin").to_path_buf(),
Path::new("/home/sbin").to_path_buf(),
Path::new("/opt").to_path_buf(),
Path::new("/opt/bin").to_path_buf(),
Path::new("/opt/sbin").to_path_buf(),
Path::new("/opt/homebrew/bin").to_path_buf(),
PathBuf::from("/usr/bin"),
PathBuf::from("/usr/local/bin"),
PathBuf::from("/bin"),
PathBuf::from("/home/bin"),
PathBuf::from("/sbin"),
PathBuf::from("/usr/sbin"),
PathBuf::from("/usr/local/sbin"),
PathBuf::from("/home/sbin"),
PathBuf::from("/opt"),
PathBuf::from("/opt/bin"),
PathBuf::from("/opt/sbin"),
PathBuf::from("/opt/homebrew/bin"),
]
}



pub fn get_user_home() -> Option<String> {
let home = env::var("HOME").or_else(|_| env::var("USERPROFILE"));
match home {
Expand Down