Skip to content

Activate base conda envs using 'name', add env_path for homebrew #23443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2024
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
2 changes: 1 addition & 1 deletion native_locator/src/conda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ fn get_root_python_environment(path: &PathBuf, manager: &EnvManager) -> Option<P
let conda_exe = manager.executable_path.to_str().unwrap().to_string();
return Some(PythonEnvironment {
display_name: None,
name: None,
name: Some("base".to_string()),
category: messaging::PythonEnvironmentCategory::Conda,
python_executable_path: Some(python_exe),
version: Some(package_info.version),
Expand Down
22 changes: 19 additions & 3 deletions native_locator/src/homebrew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
use regex::Regex;
use std::{collections::HashSet, fs::DirEntry, path::PathBuf};

fn is_symlinked_python_executable(path: DirEntry) -> Option<PathBuf> {
fn is_symlinked_python_executable(path: &DirEntry) -> Option<PathBuf> {
let path = path.path();
let name = path.file_name()?.to_string_lossy();
if !name.starts_with("python") || name.ends_with("-config") || name.ends_with("-build") {
Expand Down Expand Up @@ -50,7 +50,7 @@ impl Locator for Homebrew<'_> {
.ok()?
.filter_map(Result::ok)
{
if let Some(exe) = is_symlinked_python_executable(file) {
if let Some(exe) = is_symlinked_python_executable(&file) {
let python_version = exe.to_string_lossy().to_string();
let version = match python_regex.captures(&python_version) {
Some(captures) => match captures.get(1) {
Expand All @@ -62,14 +62,30 @@ impl Locator for Homebrew<'_> {
if reported.contains(&exe.to_string_lossy().to_string()) {
continue;
}
let env_path = match exe.parent() {
Some(path) => {
if let Some(name) = path.file_name() {
if name.to_ascii_lowercase() == "bin"
|| name.to_ascii_lowercase() == "Scripts"
{
Some(path.parent()?.to_path_buf())
} else {
Some(path.to_path_buf())
}
} else {
None
}
}
None => continue,
};
reported.insert(exe.to_string_lossy().to_string());
let env = crate::messaging::PythonEnvironment::new(
None,
None,
Some(exe.clone()),
crate::messaging::PythonEnvironmentCategory::Homebrew,
version,
None,
env_path,
None,
Some(vec![exe.to_string_lossy().to_string()]),
);
Expand Down
2 changes: 1 addition & 1 deletion native_locator/tests/conda_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ fn find_conda_from_custom_install_location() {

let expected_conda_env = PythonEnvironment {
display_name: None,
name: None,
name: Some("base".to_string()),
project_path: None,
python_executable_path: Some(conda_dir.clone().join("bin").join("python")),
category: python_finder::messaging::PythonEnvironmentCategory::Conda,
Expand Down
Loading