@@ -7,9 +7,9 @@ def main(cleanup=None):
77 import optparse
88 import os
99 import sys
10- import subprocess
1110 from rchitect .utils import Rhome , rversion
1211 from radian import __version__
12+ from .dyld import should_set_ld_library_path , set_ld_library_path , reset_dyld_insert_blas_dylib
1313
1414 try :
1515 # failed to import jedi on demand in some edge cases.
@@ -167,66 +167,16 @@ def main(cleanup=None):
167167
168168 if not r_home :
169169 raise RuntimeError ("Cannot find R binary. Expose it via the `PATH` variable." )
170+
170171
172+ if sys .platform == "darwin" :
173+ # avoid libRBlas to propagate downstream
174+ reset_dyld_insert_blas_dylib ()
175+
176+ # setup proper dynamic libraries
171177 if not sys .platform .startswith ("win" ):
172- lib_path = os .path .join (r_home , "lib" )
173- ldpaths = os .path .join (r_home , "etc" , "ldpaths" )
174-
175- if sys .platform == "darwin" :
176- libr_blas_dylib = os .path .join (lib_path , "libRblas.dylib" )
177- # avoid libRBlas to propagate downstream
178- if "DYLD_INSERT_LIBRARIES" in os .environ :
179- libs = [
180- lib
181- for lib in os .environ ["DYLD_INSERT_LIBRARIES" ].split (":" )
182- if lib != libr_blas_dylib
183- ]
184- if libs :
185- os .environ ["DYLD_INSERT_LIBRARIES" ] = ":" .join (libs )
186- else :
187- del os .environ ["DYLD_INSERT_LIBRARIES" ]
188-
189- if (
190- "R_LD_LIBRARY_PATH" not in os .environ
191- or lib_path not in os .environ ["R_LD_LIBRARY_PATH" ]
192- ):
193- if os .path .exists (ldpaths ):
194- R_LD_LIBRARY_PATH = (
195- subprocess .check_output (
196- '. "{}"; echo $R_LD_LIBRARY_PATH' .format (ldpaths ),
197- shell = True ,
198- )
199- .decode ("utf-8" )
200- .strip ()
201- )
202- elif "R_LD_LIBRARY_PATH" in os .environ :
203- R_LD_LIBRARY_PATH = os .environ ["R_LD_LIBRARY_PATH" ]
204- else :
205- R_LD_LIBRARY_PATH = lib_path
206- if lib_path not in R_LD_LIBRARY_PATH :
207- R_LD_LIBRARY_PATH = "{}:{}" .format (lib_path , R_LD_LIBRARY_PATH )
208- os .environ ["R_LD_LIBRARY_PATH" ] = R_LD_LIBRARY_PATH
209- # respect R_ARCH variable?
210- if sys .platform == "darwin" :
211- ld_library_var = "DYLD_FALLBACK_LIBRARY_PATH"
212- else :
213- ld_library_var = "LD_LIBRARY_PATH"
214- if ld_library_var in os .environ :
215- LD_LIBRARY_PATH = "{}:{}" .format (
216- R_LD_LIBRARY_PATH , os .environ [ld_library_var ]
217- )
218- else :
219- LD_LIBRARY_PATH = R_LD_LIBRARY_PATH
220- os .environ [ld_library_var ] = LD_LIBRARY_PATH
221-
222- if sys .platform == "darwin" :
223- if os .path .exists (libr_blas_dylib ):
224- if "DYLD_INSERT_LIBRARIES" not in os .environ :
225- os .environ ["DYLD_INSERT_LIBRARIES" ] = libr_blas_dylib
226- else :
227- os .environ ["DYLD_INSERT_LIBRARIES" ] = "{}:{}" .format (
228- os .environ ["DYLD_INSERT_LIBRARIES" ], libr_blas_dylib
229- )
178+ if should_set_ld_library_path (r_home ):
179+ set_ld_library_path (r_home )
230180
231181 if sys .argv [0 ].endswith ("radian" ):
232182 os .execv (sys .argv [0 ], sys .argv )
0 commit comments