@@ -10,7 +10,7 @@ use crate::{
1010use regex:: Regex ;
1111use 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 ) ;
0 commit comments