3737DEFAULT_RHINO_VERSION = 7
3838
3939
40+ # IronPython is being picky about check_output in Mono, because some arguments are not supported. Base functionallity works:
41+ def _mono_check_output (* popenargs , ** kwargs ):
42+ if "stdout" in kwargs :
43+ raise ValueError ("stdout argument not allowed, it will be overridden." )
44+ process = subprocess .Popen (stdout = subprocess .PIPE , * popenargs , ** kwargs )
45+ output , unused_err = process .communicate ()
46+ retcode = process .poll ()
47+ if retcode :
48+ cmd = kwargs .get ("args" )
49+ if cmd is None :
50+ cmd = popenargs [0 ]
51+ raise subprocess .CalledProcessError (retcode , cmd , output = output )
52+ return output
53+
54+
4055def get_python_path (location = None ):
4156 if location is None or location == "" :
4257 if WINDOWS :
@@ -120,7 +135,7 @@ def get_python_from_windows_path():
120135
121136def get_python_from_macos_path ():
122137 try :
123- python_exe = subprocess . check_output (["which" , "python" ]).split ("\n " )[0 ].strip ()
138+ python_exe = _mono_check_output (["which" , "python" ]).split ("\n " )[0 ].strip ()
124139 return python_exe
125140 except (OSError , subprocess .CalledProcessError ) as e :
126141 logger .error (
@@ -131,10 +146,34 @@ def get_python_from_macos_path():
131146
132147
133148def get_python_from_conda_env (env_name ):
149+ if MACOS :
150+ # Need to find the conda exec from the .zshrc file
151+ try :
152+ output = _mono_check_output (
153+ "source ~/.zshrc; env" , shell = True , executable = "/bin/zsh"
154+ )
155+ new_vars_list = [line .partition ("=" )[::2 ] for line in output .split ("\n " )]
156+ new_vars_dict = {name : value for (name , value ) in new_vars_list }
157+ conda_exe_path = new_vars_dict .get ("CONDA_EXE" , None )
158+ except (OSError , subprocess .CalledProcessError ):
159+ logger .warning (
160+ "Could not source ~/.zshrc file when looking for $CONDA_EXE. Continuing."
161+ )
162+ if conda_exe_path is None or not (
163+ os .path .isfile (conda_exe_path ) and os .access (conda_exe_path , os .X_OK )
164+ ):
165+ logger .warning ("Could not find $CONDA_EXE in ~/.zshrc. Continuing." )
166+ conda_exe_path = "conda"
167+
134168 try :
135- envs = json .loads (subprocess .check_output (["conda" , "env" , "list" , "--json" ]))[
136- "envs"
137- ]
169+ if WINDOWS :
170+ envs = json .loads (
171+ subprocess .check_output (["conda" , "env" , "list" , "--json" ])
172+ )["envs" ]
173+ else :
174+ envs = json .loads (
175+ _mono_check_output ([conda_exe_path , "env" , "list" , "--json" ])
176+ )["envs" ]
138177 except OSError :
139178 if WINDOWS :
140179 logger .warning (
@@ -144,7 +183,7 @@ def get_python_from_conda_env(env_name):
144183 return get_python_from_windows_path ()
145184 else :
146185 logger .warning (
147- "conda not found in your MacOS $PATH, cannot fetch environment by "
186+ "conda not found in your MacOS $PATH or ~/.zshrc , cannot fetch environment by "
148187 + "name.\n Falling back to getting python path from MacOS $PATH.\n "
149188 )
150189 return get_python_from_macos_path ()
@@ -172,7 +211,7 @@ def get_python_from_conda_env(env_name):
172211 if WINDOWS :
173212 python_exe = os .path .join (env_dir [0 ], "python.exe" )
174213 else :
175- python_exe = os .path .join (env_dir [0 ], "python" )
214+ python_exe = os .path .join (env_dir [0 ], "bin" , " python" )
176215 if os .path .isfile (python_exe ) and os .access (python_exe , os .X_OK ):
177216 return python_exe
178217 else :
@@ -618,11 +657,11 @@ def get_rhino_windows_path(version, preferred_bitness):
618657def get_rhino_macos_path (version , preferred_bitness ):
619658 if version == 7 :
620659 return os .path .join (
621- [ " Applications" , "Rhino 7.app" , "Contents" , "MacOS" , "Rhinoceros" ]
660+ "/ Applications" , "Rhino 7.app" , "Contents" , "MacOS" , "Rhinoceros"
622661 )
623662 elif version == 6 :
624663 return os .path .join (
625- [ " Applications" , "Rhinoceros.app" , "Contents" , "MacOS" , "Rhinoceros" ]
664+ "/ Applications" , "Rhinoceros.app" , "Contents" , "MacOS" , "Rhinoceros"
626665 )
627666 else :
628667 logger .error ("Unknown Rhino version {!s}." .format (version ))
0 commit comments