• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

simonsobs / so3g / 8691252237

15 Apr 2024 02:48PM UTC coverage: 49.262% (+0.08%) from 49.183%
8691252237

push

github

web-flow
Merge pull request #174 from simonsobs/use-spt3g-dload

If spt3g.dload is found, use it instead of imp module

8 of 10 new or added lines in 1 file covered. (80.0%)

1301 of 2641 relevant lines covered (49.26%)

0.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.0
/python/load_pybindings.py
1
#
2
# Based on spt3g.core.load_bindings.
3
#
4
import platform, sys, os
1✔
5
try:
1✔
6
    # Starting in spt3g 0.3-240-ga9d32d5, a custom loader is available.
7
    from spt3g import dload
1✔
NEW
8
    imp = None
×
9
except ImportError:
1✔
10
    # The imp module is deprecated; to suppress warning, upgrade spt3g ^^^.
11
    import imp
1✔
12
    dload = None
1✔
13

14
if platform.system().startswith('freebsd') or platform.system().startswith('FreeBSD'):
1✔
15
    # C++ modules are extremely fragile when loaded with RTLD_LOCAL,
16
    # which is what Python uses on FreeBSD by default, and maybe other
17
    # systems. Convince it to use RTLD_GLOBAL.
18
    
19
    # See thread by Abrahams et al:
20
    # http://mail.python.org/pipermail/python-dev/2002-May/024074.html
21
    sys.setdlopenflags(0x102)
×
22

23
def load_pybindings(paths, name=None, lib_suffix=None):
1✔
24
    """
25
    Load all non-private items from the libraries in the list "paths".
26
    Provide the full path to each library, but without extension.  The
27
    .so or .dylib will be appended depending on the system
28
    architecture.  The namespace into which the items are imported
29
    will be determined from the first path, unless name= is explicitly
30
    provided.
31
    """
32
    if lib_suffix is None:
1✔
33
        if platform.system().startswith('Darwin'):
1✔
34
            # OSX compatibility requires .dylib suffix
35
            lib_suffix = ".dylib"
×
36
        else:
37
            lib_suffix = ".so"
1✔
38
    for path in paths:
1✔
39
        if name is None:
1✔
40
            name = os.path.split(path)[1]
×
41
        # Save copy of current module def
42
        mod = sys.modules[name]
1✔
43
        if dload is None:
1✔
44
            m = imp.load_dynamic(name, path + lib_suffix)
1✔
45
        else:
NEW
46
            m = dload.load_dynamic(name, name, path + lib_suffix)
×
47
        sys.modules[name] = mod # Don't override Python mod with C++
1✔
48

49
        for (k,v) in m.__dict__.items():
1✔
50
            if not k.startswith("_"):
1✔
51
                mod.__dict__[k] = v
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc