37
37
DEFAULT_RHINO_VERSION = 7
38
38
39
39
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
+
40
55
def get_python_path (location = None ):
41
56
if location is None or location == "" :
42
57
if WINDOWS :
@@ -120,7 +135,7 @@ def get_python_from_windows_path():
120
135
121
136
def get_python_from_macos_path ():
122
137
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 ()
124
139
return python_exe
125
140
except (OSError , subprocess .CalledProcessError ) as e :
126
141
logger .error (
@@ -131,10 +146,34 @@ def get_python_from_macos_path():
131
146
132
147
133
148
def 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
+
134
168
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" ]
138
177
except OSError :
139
178
if WINDOWS :
140
179
logger .warning (
@@ -144,7 +183,7 @@ def get_python_from_conda_env(env_name):
144
183
return get_python_from_windows_path ()
145
184
else :
146
185
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 "
148
187
+ "name.\n Falling back to getting python path from MacOS $PATH.\n "
149
188
)
150
189
return get_python_from_macos_path ()
@@ -172,7 +211,7 @@ def get_python_from_conda_env(env_name):
172
211
if WINDOWS :
173
212
python_exe = os .path .join (env_dir [0 ], "python.exe" )
174
213
else :
175
- python_exe = os .path .join (env_dir [0 ], "python" )
214
+ python_exe = os .path .join (env_dir [0 ], "bin" , " python" )
176
215
if os .path .isfile (python_exe ) and os .access (python_exe , os .X_OK ):
177
216
return python_exe
178
217
else :
@@ -618,11 +657,11 @@ def get_rhino_windows_path(version, preferred_bitness):
618
657
def get_rhino_macos_path (version , preferred_bitness ):
619
658
if version == 7 :
620
659
return os .path .join (
621
- [ " Applications" , "Rhino 7.app" , "Contents" , "MacOS" , "Rhinoceros" ]
660
+ "/ Applications" , "Rhino 7.app" , "Contents" , "MacOS" , "Rhinoceros"
622
661
)
623
662
elif version == 6 :
624
663
return os .path .join (
625
- [ " Applications" , "Rhinoceros.app" , "Contents" , "MacOS" , "Rhinoceros" ]
664
+ "/ Applications" , "Rhinoceros.app" , "Contents" , "MacOS" , "Rhinoceros"
626
665
)
627
666
else :
628
667
logger .error ("Unknown Rhino version {!s}." .format (version ))
0 commit comments