diff --git a/python/load_pybindings.py b/python/load_pybindings.py index d114d14..ba956de 100644 --- a/python/load_pybindings.py +++ b/python/load_pybindings.py @@ -1,7 +1,15 @@ # # Based on spt3g.core.load_bindings. # -import platform, sys, imp, os +import platform, sys, os +try: + # Starting in spt3g 0.3-240-ga9d32d5, a custom loader is available. + from spt3g import dload + imp = None +except ImportError: + # The imp module is deprecated; to suppress warning, upgrade spt3g ^^^. + import imp + dload = None if platform.system().startswith('freebsd') or platform.system().startswith('FreeBSD'): # C++ modules are extremely fragile when loaded with RTLD_LOCAL, @@ -32,7 +40,10 @@ def load_pybindings(paths, name=None, lib_suffix=None): name = os.path.split(path)[1] # Save copy of current module def mod = sys.modules[name] - m = imp.load_dynamic(name, path + lib_suffix) + if dload is None: + m = imp.load_dynamic(name, path + lib_suffix) + else: + m = dload.load_dynamic(name, name, path + lib_suffix) sys.modules[name] = mod # Don't override Python mod with C++ for (k,v) in m.__dict__.items():