From 83ec5c102b029804608f44a9a9fbc3822cc5ee0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Mon, 25 Feb 2019 15:10:45 +0100 Subject: [PATCH] pythonPackages.shapely: use patch to set library paths --- .../python-modules/shapely/default.nix | 31 ++--- .../shapely/library-paths.patch | 109 ++++++++++++++++++ 2 files changed, 127 insertions(+), 13 deletions(-) create mode 100644 pkgs/development/python-modules/shapely/library-paths.patch diff --git a/pkgs/development/python-modules/shapely/default.nix b/pkgs/development/python-modules/shapely/default.nix index 42d82566073..220726733dc 100644 --- a/pkgs/development/python-modules/shapely/default.nix +++ b/pkgs/development/python-modules/shapely/default.nix @@ -1,5 +1,5 @@ -{ stdenv, buildPythonPackage, fetchPypi -, geos, glibcLocales, pytest, cython +{ stdenv, buildPythonPackage, fetchPypi, substituteAll +, geos, pytest, cython , numpy }: @@ -12,26 +12,31 @@ buildPythonPackage rec { sha256 = "c4b87bb61fc3de59fc1f85e71a79b0c709dc68364d9584473697aad4aa13240f"; }; - buildInputs = [ geos glibcLocales cython ]; + nativeBuildInputs = [ + geos # for geos-config + cython + ]; checkInputs = [ pytest ]; propagatedBuildInputs = [ numpy ]; - preConfigure = '' - export LANG="en_US.UTF-8"; - ''; + # environment variable used in shapely/_buildcfg.py + GEOS_LIBRARY_PATH = "${geos}/lib/libgeos_c${stdenv.hostPlatform.extensions.sharedLibrary}"; - patchPhase = let - libc = if stdenv.isDarwin then "libc.dylib" else "libc.so.6"; - in '' - sed -i "s|_lgeos = load_dll('geos_c', fallbacks=.*)|_lgeos = load_dll('geos_c', fallbacks=['${geos}/lib/libgeos_c${stdenv.hostPlatform.extensions.sharedLibrary}'])|" shapely/geos.py - sed -i "s|free = load_dll('c').free|free = load_dll('c', fallbacks=['${stdenv.cc.libc}/lib/${libc}']).free|" shapely/geos.py - ''; + patches = [ + (substituteAll { + src = ./library-paths.patch; + libgeos_c = GEOS_LIBRARY_PATH; + libc = "${stdenv.cc.libc}/lib/libc${stdenv.hostPlatform.extensions.sharedLibrary}" + + stdenv.lib.optionalString (!stdenv.isDarwin) ".6"; + }) + ]; # Disable the tests that improperly try to use the built extensions checkPhase = '' - py.test -k 'not test_vectorized and not test_fallbacks' tests + rm -r shapely # prevent import of local shapely + py.test tests ''; meta = with stdenv.lib; { diff --git a/pkgs/development/python-modules/shapely/library-paths.patch b/pkgs/development/python-modules/shapely/library-paths.patch new file mode 100644 index 00000000000..6137e758182 --- /dev/null +++ b/pkgs/development/python-modules/shapely/library-paths.patch @@ -0,0 +1,109 @@ +diff --git a/shapely/geos.py b/shapely/geos.py +index 09bf1ab..837aa98 100644 +--- a/shapely/geos.py ++++ b/shapely/geos.py +@@ -55,100 +55,10 @@ def load_dll(libname, fallbacks=None, mode=DEFAULT_MODE): + "Could not find lib {0} or load any of its variants {1}.".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) +- else: +- alt_paths = [ +- 'libgeos_c.so.1', +- 'libgeos_c.so', +- # anaconda +- os.path.join(sys.prefix, "lib", "libgeos_c.so"), +- ] +- _lgeos = load_dll('geos_c', fallbacks=alt_paths) +- free = load_dll('c').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): +- _lgeos = CDLL(geos_whl_dylib) +- LOG.debug("Found GEOS DLL: %r, using it.", _lgeos) +- +- 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 = [ +- # anaconda +- os.path.join(sys.prefix, "lib", "libgeos_c.dylib"), +- # The Framework build from Kyng Chaos +- "/Library/Frameworks/GEOS.framework/Versions/Current/GEOS", +- # macports +- '/opt/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': +- try: +- egg_dlls = os.path.abspath( +- os.path.join(os.path.dirname(__file__), 'DLLs')) +- if 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", fallbacks=[ +- os.path.join(sys.prefix, "Library", "lib", "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 = 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():