27 from __future__
import print_function
36 SHARED_LIB_EXTENSION_LIST = (
'.so',
'.dylib')
37 LIB_EXCEPTION_LIST = (
'_lsstcppimport.so',)
45 options = (
'os',
'DLFCN',
'ctypes')
48 m = importlib.import_module(mod)
49 if RTLD_GLOBAL
is None and hasattr(m,
"RTLD_GLOBAL"):
50 RTLD_GLOBAL = m.RTLD_GLOBAL
51 if RTLD_NOW
is None and hasattr(m,
"RTLD_NOW"):
55 if RTLD_GLOBAL
is not None and RTLD_NOW
is not None:
59 if RTLD_GLOBAL
is None:
60 raise NameError(
"RTLD_GLOBAL constant can not be determined")
69 DLFLAGS = RTLD_GLOBAL | RTLD_NOW
80 if 'orig_imp_load_module' not in locals():
81 orig_imp_load_module = imp.load_module
83 @functools.wraps(orig_imp_load_module)
85 pathParts = args[1].split(os.path.sep)
86 extension = os.path.splitext(pathParts[-1])[-1]
93 lsstIdx = [i
for i, el
in enumerate(pathParts)
if el ==
'python']
94 if pathParts[-1]
in LIB_EXCEPTION_LIST
or (extension
in SHARED_LIB_EXTENSION_LIST
95 and pathParts[-1].startswith(
'_')
96 and 'lsst' in [pathParts[i+1]
for i
in lsstIdx]):
98 originalDLFlags = sys.getdlopenflags()
100 sys.setdlopenflags(DLFLAGS)
105 sys.setdlopenflags(originalDLFlags)
109 imp.load_module = imp_load_module
115 "Could not import lsstcppimport; please ensure the base package has been built (not just setup).\n",