From 18437fb33d2002cdf0423fa4dff0169d0f327bf7 Mon Sep 17 00:00:00 2001 From: Ivan Mincik Date: Wed, 6 Dec 2023 16:49:42 +0100 Subject: [PATCH] python3Packages.shapely: keep version 1.8 Keep old version of package due to requirements of following packages: * kikit --- .../python-modules/shapely/1.8.nix | 89 +++++++++++++++++++ .../shapely/library-paths.patch | 31 +++++++ pkgs/top-level/python-packages.nix | 2 + 3 files changed, 122 insertions(+) create mode 100644 pkgs/development/python-modules/shapely/1.8.nix create mode 100644 pkgs/development/python-modules/shapely/library-paths.patch diff --git a/pkgs/development/python-modules/shapely/1.8.nix b/pkgs/development/python-modules/shapely/1.8.nix new file mode 100644 index 000000000000..2afbdba3d79b --- /dev/null +++ b/pkgs/development/python-modules/shapely/1.8.nix @@ -0,0 +1,89 @@ +{ lib +, stdenv +, buildPythonPackage +, fetchPypi +, pytestCheckHook +, pythonOlder +, substituteAll + +, cython +, geos311 +, numpy +, oldest-supported-numpy +, setuptools +, wheel +}: + +buildPythonPackage rec { + pname = "Shapely"; + version = "1.8.5"; + format = "pyproject"; + + disabled = pythonOlder "3.7"; + + src = fetchPypi { + inherit pname version; + hash = "sha256-6CttYOz7EkEgyI/hBqR4WWu+qxQhFtfn9ko2TayQKpI="; + }; + + # Environment variable used in shapely/_buildcfg.py + GEOS_LIBRARY_PATH = "${geos311}/lib/libgeos_c${stdenv.hostPlatform.extensions.sharedLibrary}"; + + patches = [ + # Patch to search form GOES .so/.dylib files in a Nix-aware way + (substituteAll { + src = ./library-paths.patch; + libgeos_c = GEOS_LIBRARY_PATH; + libc = lib.optionalString (!stdenv.isDarwin) "${stdenv.cc.libc}/lib/libc${stdenv.hostPlatform.extensions.sharedLibrary}.6"; + }) + ]; + + postPatch = '' + substituteInPlace pyproject.toml --replace "setuptools<64" "setuptools" + ''; + + nativeBuildInputs = [ + cython + geos311 # for geos-config + oldest-supported-numpy + setuptools + wheel + ]; + + buildInputs = [ + geos311 + ]; + + propagatedBuildInputs = [ + numpy + ]; + + nativeCheckInputs = [ + pytestCheckHook + ]; + + preCheck = '' + rm -r shapely # prevent import of local shapely + ''; + + disabledTests = lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [ + # FIXME(lf-): these logging tests are broken, which is definitely our + # fault. I've tried figuring out the cause and failed. + # + # It is apparently some sandbox or no-sandbox related thing on macOS only + # though. + "test_error_handler_exception" + "test_error_handler" + "test_info_handler" + ]; + + pythonImportsCheck = [ "shapely" ]; + + meta = with lib; { + changelog = "https://github.com/shapely/shapely/blob/${version}/CHANGES.txt"; + description = "Manipulation and analysis of geometric objects"; + homepage = "https://github.com/shapely/shapely"; + license = licenses.bsd3; + maintainers = teams.geospatial.members; + }; +} 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 000000000000..12f93e757f9a --- /dev/null +++ b/pkgs/development/python-modules/shapely/library-paths.patch @@ -0,0 +1,31 @@ +diff --git a/shapely/geos.py b/shapely/geos.py +index 88c5f53..1ccd6e4 100644 +--- a/shapely/geos.py ++++ b/shapely/geos.py +@@ -96,6 +96,7 @@ if sys.platform.startswith('linux'): + alt_paths = [ + 'libgeos_c.so.1', + 'libgeos_c.so', ++ '@libgeos_c@', + ] + _lgeos = load_dll('geos_c', fallbacks=alt_paths) + +@@ -160,6 +161,7 @@ elif sys.platform == 'darwin': + "/usr/local/lib/libgeos_c.dylib", + # homebrew Apple Silicon + "/opt/homebrew/lib/libgeos_c.dylib", ++ "@libgeos_c@", + ] + _lgeos = load_dll('geos_c', fallbacks=alt_paths) + +diff --git a/tests/test_dlls.py b/tests/test_dlls.py +index c71da8e..c36262c 100644 +--- a/tests/test_dlls.py ++++ b/tests/test_dlls.py +@@ -18,4 +18,5 @@ class LoadingTestCase(unittest.TestCase): + '/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.so', ++ '@libgeos_c@']) diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index e965fe2441f2..cebbd1d18198 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -12933,6 +12933,8 @@ self: super: with self; { shapely = callPackage ../development/python-modules/shapely { }; + shapely18 = callPackage ../development/python-modules/shapely/1.8.nix { }; + shaperglot = callPackage ../development/python-modules/shaperglot { }; sharedmem = callPackage ../development/python-modules/sharedmem { };