about summary refs log tree commit diff
path: root/pkgs/development
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/development')
-rw-r--r--pkgs/development/python-modules/h3/default.nix35
-rw-r--r--pkgs/development/python-modules/h3/disable-custom-install.patch41
-rw-r--r--pkgs/development/python-modules/h3/hardcode-h3-path.patch19
3 files changed, 95 insertions, 0 deletions
diff --git a/pkgs/development/python-modules/h3/default.nix b/pkgs/development/python-modules/h3/default.nix
new file mode 100644
index 000000000000..d98a053c4189
--- /dev/null
+++ b/pkgs/development/python-modules/h3/default.nix
@@ -0,0 +1,35 @@
+{ stdenv
+, buildPythonPackage
+, cmake
+, fetchPypi
+, h3
+, python
+}:
+
+buildPythonPackage rec {
+  pname = "h3";
+  version = "3.4.3";
+
+  src = fetchPypi {
+    inherit pname version;
+    sha256 = "07dlqpr1r4kzb3gci395plpss8gxvvrij40l6w0mylyg7fkab4m2";
+  };
+
+  patches = [
+    ./disable-custom-install.patch
+    ./hardcode-h3-path.patch
+  ];
+
+  preBuild = ''
+    substituteInPlace h3/h3.py \
+      --subst-var-by libh3_path ${h3}/lib/libh3${stdenv.hostPlatform.extensions.sharedLibrary}
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = "https://github.com/uber/h3-py";
+    description = "This library provides Python bindings for the H3 Core Library.";
+    license = licenses.asl20;
+    platforms = platforms.unix ++ platforms.darwin;
+    maintainers = [ maintainers.kalbasit ];
+  };
+}
diff --git a/pkgs/development/python-modules/h3/disable-custom-install.patch b/pkgs/development/python-modules/h3/disable-custom-install.patch
new file mode 100644
index 000000000000..981e3b6e2fc6
--- /dev/null
+++ b/pkgs/development/python-modules/h3/disable-custom-install.patch
@@ -0,0 +1,41 @@
+diff --git a/setup.py b/setup.py
+index 8e1c220..45297b6 100644
+--- a/setup.py
++++ b/setup.py
+@@ -25,20 +25,6 @@ class CustomBuildExtCommand(build_ext):
+         install_h3(h3_version)
+
+
+-# Tested with wheel v0.29.0
+-class BinaryDistribution(Distribution):
+-    def __init__(self, attrs=None):
+-        Distribution.__init__(self, attrs)
+-        # The values used for the name and sources in the Extension below are
+-        # not important, because we override the build_ext command above.
+-        # The normal C extension building logic is never invoked, and is
+-        # replaced with our own custom logic. However, ext_modules cannot be
+-        # empty, because this signals to other parts of distutils that our
+-        # package contains C extensions and thus needs to be built for
+-        # different platforms separately.
+-        self.ext_modules = [Extension('h3c', [])]
+-
+-
+ long_description = open('README.rst').read()
+
+ setup(
+@@ -52,14 +38,10 @@ setup(
+     url='https://github.com/uber/h3-py.git',
+     packages=find_packages(exclude=['tests', 'tests.*']),
+     install_requires=[],
+-    cmdclass={
+-        'build_ext': CustomBuildExtCommand,
+-    },
+     package_data={
+         'h-py':
+         ['out/*.dylib' if platform.system() == 'Darwin' else (
+             'out/*.dll' if platform.system() == 'Windows' else
+             'out/*.so.*')]
+     },
+-    license='Apache License 2.0',
+-    distclass=BinaryDistribution)
++    license='Apache License 2.0')
diff --git a/pkgs/development/python-modules/h3/hardcode-h3-path.patch b/pkgs/development/python-modules/h3/hardcode-h3-path.patch
new file mode 100644
index 000000000000..87549f298d74
--- /dev/null
+++ b/pkgs/development/python-modules/h3/hardcode-h3-path.patch
@@ -0,0 +1,19 @@
+diff --git a/h3/h3.py b/h3/h3.py
+index 18cf168..2cc7812 100644
+--- a/h3/h3.py
++++ b/h3/h3.py
+@@ -34,13 +34,7 @@ from ctypes import (
+     POINTER,
+ )
+
+-_dirname = os.path.dirname(__file__)
+-libh3_path = ('{}/{}'.format(_dirname, 'out/libh3.1.dylib')
+-              if platform.system() == 'Darwin' else (
+-              '{}/{}'.format(_dirname, 'out/h3.dll') if platform.system() == 'Windows' else
+-              '{}/{}'.format(_dirname, 'out/libh3.so.1')))
+-
+-libh3 = cdll.LoadLibrary(libh3_path)
++libh3 = cdll.LoadLibrary('@libh3_path@')
+
+ # Type of an H3 index
+ H3Index = c_ulonglong