Merge pull request #119126 from fabaff/pycomfoconnect
[NixPkgs.git] / pkgs / development / python-modules / shapely / library-paths.patch
blob7681fb1d9bb20cf381d0fc96434601cd8b274dd2
1 diff --git a/shapely/geos.py b/shapely/geos.py
2 index d5a67d2..19b7ffc 100644
3 --- a/shapely/geos.py
4 +++ b/shapely/geos.py
5 @@ -61,127 +61,17 @@ def load_dll(libname, fallbacks=None, mode=DEFAULT_MODE):
6 "Could not find lib {} or load any of its variants {}.".format(
7 libname, fallbacks or []))
9 -_lgeos = None
11 -if sys.platform.startswith('linux'):
12 - # Test to see if we have a wheel repaired by 'auditwheel' containing its
13 - # own libgeos_c
14 - geos_whl_so = glob.glob(os.path.abspath(os.path.join(os.path.dirname(
15 - __file__), '.libs/libgeos_c-*.so.*')))
16 - if len(geos_whl_so) == 1:
17 - _lgeos = CDLL(geos_whl_so[0])
18 - LOG.debug("Found GEOS DLL: %r, using it.", _lgeos)
19 - elif hasattr(sys, 'frozen'):
20 - geos_pyinstaller_so = glob.glob(os.path.join(sys.prefix, 'libgeos_c-*.so.*'))
21 - if len(geos_pyinstaller_so) == 1:
22 - _lgeos = CDLL(geos_pyinstaller_so[0])
23 - LOG.debug("Found GEOS DLL: %r, using it.", _lgeos)
24 - elif os.getenv('CONDA_PREFIX', ''):
25 - # conda package.
26 - _lgeos = CDLL(os.path.join(sys.prefix, 'lib', 'libgeos_c.so'))
27 - else:
28 - alt_paths = [
29 - 'libgeos_c.so.1',
30 - 'libgeos_c.so',
31 - ]
32 - _lgeos = load_dll('geos_c', fallbacks=alt_paths)
33 - # Necessary for environments with only libc.musl
34 - c_alt_paths = [
35 - 'libc.musl-x86_64.so.1'
36 - ]
37 - free = load_dll('c', fallbacks=c_alt_paths).free
38 - free.argtypes = [c_void_p]
39 - free.restype = None
41 -elif sys.platform == 'darwin':
42 - # Test to see if we have a delocated wheel with a GEOS dylib.
43 - geos_whl_dylib = os.path.abspath(os.path.join(os.path.dirname(
44 - __file__), '.dylibs/libgeos_c.1.dylib'))
46 - if os.path.exists(geos_whl_dylib):
47 - handle = CDLL(None)
48 - if hasattr(handle, "initGEOS_r"):
49 - LOG.debug("GEOS already loaded")
50 - _lgeos = handle
51 - else:
52 - _lgeos = CDLL(geos_whl_dylib)
53 - LOG.debug("Found GEOS DLL: %r, using it.", _lgeos)
55 - elif os.getenv('CONDA_PREFIX', ''):
56 - # conda package.
57 - _lgeos = CDLL(os.path.join(sys.prefix, 'lib', 'libgeos_c.dylib'))
58 - else:
59 - if hasattr(sys, 'frozen'):
60 - try:
61 - # .app file from py2app
62 - alt_paths = [os.path.join(
63 - os.environ['RESOURCEPATH'], '..', 'Frameworks',
64 - 'libgeos_c.dylib')]
65 - except KeyError:
66 - # binary from pyinstaller
67 - alt_paths = [
68 - os.path.join(sys.executable, 'libgeos_c.dylib')]
69 - if hasattr(sys, '_MEIPASS'):
70 - alt_paths.append(
71 - os.path.join(sys._MEIPASS, 'libgeos_c.1.dylib'))
72 - else:
73 - alt_paths = [
74 - # The Framework build from Kyng Chaos
75 - "/Library/Frameworks/GEOS.framework/Versions/Current/GEOS",
76 - # macports
77 - '/opt/local/lib/libgeos_c.dylib',
78 - # homebrew
79 - '/usr/local/lib/libgeos_c.dylib',
80 - ]
81 - _lgeos = load_dll('geos_c', fallbacks=alt_paths)
83 - # ctypes.CDLL(None) internally calls dlopen(NULL), and as the dlopen
84 - # manpage says, "If filename is NULL, then the returned handle is for the
85 - # main program". This way we can let the linker do the work to figure out
86 - # which libc Python is actually using.
87 - free = CDLL(None).free
88 - free.argtypes = [c_void_p]
89 - free.restype = None
91 -elif sys.platform == 'win32':
92 - if os.getenv('CONDA_PREFIX', ''):
93 - # conda package.
94 - _lgeos = CDLL(os.path.join(sys.prefix, 'Library', 'bin', 'geos_c.dll'))
95 - else:
96 - try:
97 - egg_dlls = os.path.abspath(
98 - os.path.join(os.path.dirname(__file__), 'DLLs'))
99 - if hasattr(sys, '_MEIPASS'):
100 - wininst_dlls = sys._MEIPASS
101 - elif hasattr(sys, "frozen"):
102 - wininst_dlls = os.path.normpath(
103 - os.path.abspath(sys.executable + '../../DLLS'))
104 - else:
105 - wininst_dlls = os.path.abspath(os.__file__ + "../../../DLLs")
106 - original_path = os.environ['PATH']
107 - os.environ['PATH'] = "%s;%s;%s" % \
108 - (egg_dlls, wininst_dlls, original_path)
109 - _lgeos = load_dll("geos_c.dll")
110 - except (ImportError, WindowsError, OSError):
111 - raise
113 - def free(m):
114 - try:
115 - cdll.msvcrt.free(m)
116 - except WindowsError:
117 - # XXX: See http://trac.gispython.org/projects/PCL/ticket/149
118 - pass
120 -elif sys.platform == 'sunos5':
121 - _lgeos = load_dll('geos_c', fallbacks=['libgeos_c.so.1', 'libgeos_c.so'])
122 - free = CDLL('libc.so.1').free
123 - free.argtypes = [c_void_p]
124 - free.restype = None
125 -else: # other *nix systems
126 - _lgeos = load_dll('geos_c', fallbacks=['libgeos_c.so.1', 'libgeos_c.so'])
127 - free = load_dll('c', fallbacks=['libc.so.6']).free
128 - free.argtypes = [c_void_p]
129 - free.restype = None
130 +_lgeos = CDLL('@libgeos_c@')
131 +if sys.platform == 'darwin':
132 + # ctypes.CDLL(None) internally calls dlopen(NULL), and as the dlopen
133 + # manpage says, "If filename is NULL, then the returned handle is for the
134 + # main program". This way we can let the linker do the work to figure out
135 + # which libc Python is actually using.
136 + free = CDLL(None).free
137 +else:
138 + free = CDLL('@libc@').free
139 +free.argtypes = [c_void_p]
140 +free.restype = None
143 def _geos_version():
144 diff --git a/tests/test_dlls.py b/tests/test_dlls.py
145 index 35f9cc2..3dfcaac 100644
146 --- a/tests/test_dlls.py
147 +++ b/tests/test_dlls.py
148 @@ -12,12 +12,7 @@ class LoadingTestCase(unittest.TestCase):
149 @unittest.skipIf(sys.platform == "win32", "FIXME: adapt test for win32")
150 def test_fallbacks(self):
151 load_dll('geos_c', fallbacks=[
152 - os.path.join(sys.prefix, "lib", "libgeos_c.dylib"), # anaconda (Mac OS X)
153 - '/opt/local/lib/libgeos_c.dylib', # MacPorts
154 - '/usr/local/lib/libgeos_c.dylib', # homebrew (Mac OS X)
155 - os.path.join(sys.prefix, "lib", "libgeos_c.so"), # anaconda (Linux)
156 - 'libgeos_c.so.1',
157 - 'libgeos_c.so'])
158 + '@libgeos_c@'])
161 def test_suite():