3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/pkgs/development/python-modules/shapely/library-paths.patch

151 lines
5.6 KiB
Diff
Raw Normal View History

diff --git a/shapely/geos.py b/shapely/geos.py
2020-03-29 12:15:20 +01:00
index d5a67d2..19b7ffc 100644
--- a/shapely/geos.py
+++ b/shapely/geos.py
2020-03-29 12:15:20 +01:00
@@ -61,123 +61,11 @@ 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
-
-if sys.platform.startswith('linux'):
- # Test to see if we have a wheel repaired by 'auditwheel' containing its
- # own libgeos_c
- geos_whl_so = glob.glob(os.path.abspath(os.path.join(os.path.dirname(
- __file__), '.libs/libgeos_c-*.so.*')))
- if len(geos_whl_so) == 1:
- _lgeos = CDLL(geos_whl_so[0])
- LOG.debug("Found GEOS DLL: %r, using it.", _lgeos)
2020-03-29 12:15:20 +01:00
- 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 os.getenv('CONDA_PREFIX', ''):
- # 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)
2020-03-29 12:15:20 +01:00
- # Necessary for environments with only libc.musl
- c_alt_paths = [
- 'libc.musl-x86_64.so.1'
- ]
- free = load_dll('c', fallbacks=c_alt_paths).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'))
2020-03-29 12:15:20 +01:00
-
- if os.path.exists(geos_whl_dylib):
2020-03-29 12:15:20 +01:00
- 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)
-
2020-03-29 12:15:20 +01:00
- elif os.getenv('CONDA_PREFIX', ''):
- # 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:
- # binary from pyinstaller
- alt_paths = [
- os.path.join(sys.executable, 'libgeos_c.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',
2020-03-29 12:15:20 +01:00
- # homebrew
- '/usr/local/lib/libgeos_c.dylib',
- ]
- _lgeos = load_dll('geos_c', fallbacks=alt_paths)
-
- free = load_dll('c').free
- free.argtypes = [c_void_p]
- free.restype = None
-
-elif sys.platform == 'win32':
2020-03-29 12:15:20 +01:00
- if os.getenv('CONDA_PREFIX', ''):
- # conda package.
- _lgeos = CDLL(os.path.join(sys.prefix, 'Library', 'bin', 'geos_c.dll'))
- else:
- try:
2020-03-29 12:15:20 +01:00
- 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
-
2020-03-29 12:15:20 +01:00
- 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 = CDLL('libc.so.1').free
- 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 = load_dll('c', fallbacks=['libc.so.6']).free
- free.argtypes = [c_void_p]
- free.restype = None
+_lgeos = CDLL('@libgeos_c@')
+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 35f9cc2..3dfcaac 100644
--- a/tests/test_dlls.py
+++ b/tests/test_dlls.py
@@ -12,12 +12,7 @@ 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)
- os.path.join(sys.prefix, "lib", "libgeos_c.so"), # anaconda (Linux)
- 'libgeos_c.so.1',
- 'libgeos_c.so'])
+ '@libgeos_c@'])
def test_suite():