Skip to content

Commit

Permalink
Merge pull request #174 from simonsobs/use-spt3g-dload
Browse files Browse the repository at this point in the history
If spt3g.dload is found, use it instead of imp module
  • Loading branch information
mhasself authored Apr 15, 2024
2 parents f226e8f + 2831126 commit 22ce3b5
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions python/load_pybindings.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit 22ce3b5

Please sign in to comment.