Skip to content

Commit 5a1b295

Browse files
authored
Activate base conda envs using 'name', add env_path for homebrew (#23443)
1 parent 0a88ed3 commit 5a1b295

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

native_locator/src/conda.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ fn get_root_python_environment(path: &PathBuf, manager: &EnvManager) -> Option<P
632632
let conda_exe = manager.executable_path.to_str().unwrap().to_string();
633633
return Some(PythonEnvironment {
634634
display_name: None,
635-
name: None,
635+
name: Some("base".to_string()),
636636
category: messaging::PythonEnvironmentCategory::Conda,
637637
python_executable_path: Some(python_exe),
638638
version: Some(package_info.version),

native_locator/src/homebrew.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
use regex::Regex;
1111
use std::{collections::HashSet, fs::DirEntry, path::PathBuf};
1212

13-
fn is_symlinked_python_executable(path: DirEntry) -> Option<PathBuf> {
13+
fn is_symlinked_python_executable(path: &DirEntry) -> Option<PathBuf> {
1414
let path = path.path();
1515
let name = path.file_name()?.to_string_lossy();
1616
if !name.starts_with("python") || name.ends_with("-config") || name.ends_with("-build") {
@@ -50,7 +50,7 @@ impl Locator for Homebrew<'_> {
5050
.ok()?
5151
.filter_map(Result::ok)
5252
{
53-
if let Some(exe) = is_symlinked_python_executable(file) {
53+
if let Some(exe) = is_symlinked_python_executable(&file) {
5454
let python_version = exe.to_string_lossy().to_string();
5555
let version = match python_regex.captures(&python_version) {
5656
Some(captures) => match captures.get(1) {
@@ -62,14 +62,30 @@ impl Locator for Homebrew<'_> {
6262
if reported.contains(&exe.to_string_lossy().to_string()) {
6363
continue;
6464
}
65+
let env_path = match exe.parent() {
66+
Some(path) => {
67+
if let Some(name) = path.file_name() {
68+
if name.to_ascii_lowercase() == "bin"
69+
|| name.to_ascii_lowercase() == "Scripts"
70+
{
71+
Some(path.parent()?.to_path_buf())
72+
} else {
73+
Some(path.to_path_buf())
74+
}
75+
} else {
76+
None
77+
}
78+
}
79+
None => continue,
80+
};
6581
reported.insert(exe.to_string_lossy().to_string());
6682
let env = crate::messaging::PythonEnvironment::new(
6783
None,
6884
None,
6985
Some(exe.clone()),
7086
crate::messaging::PythonEnvironmentCategory::Homebrew,
7187
version,
72-
None,
88+
env_path,
7389
None,
7490
Some(vec![exe.to_string_lossy().to_string()]),
7591
);

native_locator/tests/conda_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ fn find_conda_from_custom_install_location() {
182182

183183
let expected_conda_env = PythonEnvironment {
184184
display_name: None,
185-
name: None,
185+
name: Some("base".to_string()),
186186
project_path: None,
187187
python_executable_path: Some(conda_dir.clone().join("bin").join("python")),
188188
category: python_finder::messaging::PythonEnvironmentCategory::Conda,

0 commit comments

Comments
 (0)