about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/python-modules/shapely/library-paths.patch
blob: d55630be9c10926baa937f9bf02894922bc7f132 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
diff --git a/shapely/geos.py b/shapely/geos.py
index 4619732..1abdb5e 100644
--- a/shapely/geos.py
+++ b/shapely/geos.py
@@ -55,148 +55,21 @@ def load_dll(libname, fallbacks=None, mode=DEFAULT_MODE):
             "Could not find lib {} or load any of its variants {}.".format(
                 libname, fallbacks or []))
 
-_lgeos = None
 def exists_conda_env():
     """Does this module exist in a conda environment?"""
     return os.path.exists(os.path.join(sys.prefix, 'conda-meta'))
 
-
-if sys.platform.startswith('linux'):
-    # Test to see if we have a wheel repaired by auditwheel which contains its
-    # own libgeos_c. Note: auditwheel 3.1 changed the location of libs.
-    geos_whl_so = glob.glob(
-        os.path.abspath(os.path.join(os.path.dirname(__file__), ".libs/libgeos*.so*"))
-    ) or glob.glob(
-        os.path.abspath(
-            os.path.join(
-                os.path.dirname(__file__), "..", "Shapely.libs", "libgeos*.so*"
-            )
-        )
-    )
-
-    if len(geos_whl_so) > 0:
-        # We have observed problems with CDLL of libgeos_c not automatically
-        # loading the sibling c++ library since the change made by auditwheel
-        # 3.1, so we explicitly load them both.
-        geos_whl_so = sorted(geos_whl_so)
-        CDLL(geos_whl_so[0])
-        _lgeos = CDLL(geos_whl_so[-1])
-        LOG.debug("Found GEOS DLL: %r, using it.", _lgeos)
-
-    elif hasattr(sys, 'frozen'):
-        geos_pyinstaller_so = glob.glob(os.path.join(sys.prefix, 'libgeos_c-*.so.*'))
-        if len(geos_pyinstaller_so) >= 1:
-            _lgeos = CDLL(geos_pyinstaller_so[0])
-            LOG.debug("Found GEOS DLL: %r, using it.", _lgeos)
-    elif exists_conda_env():
-        # conda package.
-        _lgeos = CDLL(os.path.join(sys.prefix, 'lib', 'libgeos_c.so'))
-    else:
-        alt_paths = [
-            'libgeos_c.so.1',
-            'libgeos_c.so',
-        ]
-        _lgeos = load_dll('geos_c', fallbacks=alt_paths)
-
+_lgeos = CDLL('@libgeos_c@')
+if sys.platform == 'darwin':
     # ctypes.CDLL(None) internally calls dlopen(NULL), and as the dlopen
     # manpage says, "If filename is NULL, then the returned handle is for the
     # main program". This way we can let the linker do the work to figure out
     # which libc Python is actually using.
     free = CDLL(None).free
-    free.argtypes = [c_void_p]
-    free.restype = None
-
-elif sys.platform == 'darwin':
-    # Test to see if we have a delocated wheel with a GEOS dylib.
-    geos_whl_dylib = os.path.abspath(os.path.join(os.path.dirname(
-        __file__), '.dylibs/libgeos_c.1.dylib'))
-
-    if os.path.exists(geos_whl_dylib):
-        handle = CDLL(None)
-        if hasattr(handle, "initGEOS_r"):
-            LOG.debug("GEOS already loaded")
-            _lgeos = handle
-        else:
-            _lgeos = CDLL(geos_whl_dylib)
-            LOG.debug("Found GEOS DLL: %r, using it.", _lgeos)
-
-    elif exists_conda_env():
-        # conda package.
-        _lgeos = CDLL(os.path.join(sys.prefix, 'lib', 'libgeos_c.dylib'))
-    else:
-        if hasattr(sys, 'frozen'):
-            try:
-                # .app file from py2app
-                alt_paths = [os.path.join(
-                    os.environ['RESOURCEPATH'], '..', 'Frameworks',
-                    'libgeos_c.dylib')]
-            except KeyError:
-                alt_paths = [
-                    # binary from pyinstaller
-                    os.path.join(sys.executable, 'libgeos_c.dylib'),
-                    # .app from cx_Freeze
-                    os.path.join(os.path.dirname(sys.executable), 'libgeos_c.1.dylib')]
-                if hasattr(sys, '_MEIPASS'):
-                    alt_paths.append(
-                        os.path.join(sys._MEIPASS, 'libgeos_c.1.dylib'))
-        else:
-            alt_paths = [
-                # The Framework build from Kyng Chaos
-                "/Library/Frameworks/GEOS.framework/Versions/Current/GEOS",
-                # macports
-                '/opt/local/lib/libgeos_c.dylib',
-                # homebrew Intel
-                '/usr/local/lib/libgeos_c.dylib',
-                # homebrew Apple Silicon
-                '/opt/homebrew/lib/libgeos_c.dylib',
-            ]
-        _lgeos = load_dll('geos_c', fallbacks=alt_paths)
-
-    free = CDLL(None).free
-    free.argtypes = [c_void_p]
-    free.restype = None
-
-elif sys.platform == 'win32':
-    _conda_dll_path = os.path.join(sys.prefix, 'Library', 'bin', 'geos_c.dll')
-    if exists_conda_env() and os.path.exists(_conda_dll_path):
-        # conda package.
-        _lgeos = CDLL(_conda_dll_path)
-    else:
-        try:
-            egg_dlls = os.path.abspath(
-                os.path.join(os.path.dirname(__file__), 'DLLs'))
-            if hasattr(sys, '_MEIPASS'):
-                wininst_dlls = sys._MEIPASS
-            elif hasattr(sys, "frozen"):
-                wininst_dlls = os.path.normpath(
-                    os.path.abspath(sys.executable + '../../DLLS'))
-            else:
-                wininst_dlls = os.path.abspath(os.__file__ + "../../../DLLs")
-            original_path = os.environ['PATH']
-            os.environ['PATH'] = "%s;%s;%s" % \
-                (egg_dlls, wininst_dlls, original_path)
-            _lgeos = load_dll("geos_c.dll")
-        except (ImportError, WindowsError, OSError):
-            raise
-
-        def free(m):
-            try:
-                cdll.msvcrt.free(m)
-            except WindowsError:
-                # XXX: See http://trac.gispython.org/projects/PCL/ticket/149
-                pass
-
-elif sys.platform == 'sunos5':
-    _lgeos = load_dll('geos_c', fallbacks=['libgeos_c.so.1', 'libgeos_c.so'])
-    free.restype = None
-    free.argtypes = [c_void_p]
-    free.restype = None
-
-else:  # other *nix systems
-    _lgeos = load_dll('geos_c', fallbacks=['libgeos_c.so.1', 'libgeos_c.so'])
-    free = CDLL(None).free
-    free.argtypes = [c_void_p]
-    free.restype = None
+else:
+    free = CDLL('@libc@').free
+free.argtypes = [c_void_p]
+free.restype = None
 
 
 def _geos_version():
diff --git a/tests/test_dlls.py b/tests/test_dlls.py
index c71da8e..fae9da6 100644
--- a/tests/test_dlls.py
+++ b/tests/test_dlls.py
@@ -12,10 +12,4 @@ class LoadingTestCase(unittest.TestCase):
     @unittest.skipIf(sys.platform == "win32", "FIXME: adapt test for win32")
     def test_fallbacks(self):
         load_dll('geos_c', fallbacks=[
-            os.path.join(sys.prefix, "lib", "libgeos_c.dylib"), # anaconda (Mac OS X)
-            '/opt/local/lib/libgeos_c.dylib',     # MacPorts
-            '/usr/local/lib/libgeos_c.dylib',     # homebrew (Mac OS X)
-            '/opt/homebrew/lib/libgeos_c.dylib',  # homebrew (macOS)
-            os.path.join(sys.prefix, "lib", "libgeos_c.so"), # anaconda (Linux)
-            'libgeos_c.so.1',
-            'libgeos_c.so'])
+            '@libgeos_c@'])