about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWael M. Nasreddine <wael.nasreddine@gmail.com>2019-07-16 17:39:52 -0700
committerJon <jonringer@users.noreply.github.com>2020-01-06 13:51:00 -0800
commitba3aeb1ca104f8ca7ad30766e54976f0c89736db (patch)
tree3d12d81f2f66bd22783760904ce3e742ba670f6b
parent9d9bba120f16df90b86d31764c4a981063c0350b (diff)
downloadnixlib-ba3aeb1ca104f8ca7ad30766e54976f0c89736db.tar
nixlib-ba3aeb1ca104f8ca7ad30766e54976f0c89736db.tar.gz
nixlib-ba3aeb1ca104f8ca7ad30766e54976f0c89736db.tar.bz2
nixlib-ba3aeb1ca104f8ca7ad30766e54976f0c89736db.tar.lz
nixlib-ba3aeb1ca104f8ca7ad30766e54976f0c89736db.tar.xz
nixlib-ba3aeb1ca104f8ca7ad30766e54976f0c89736db.tar.zst
nixlib-ba3aeb1ca104f8ca7ad30766e54976f0c89736db.zip
pythonPackages.h3: init at 3.4.3
-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
-rw-r--r--pkgs/top-level/python-packages.nix2
4 files changed, 97 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
diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix
index fb5504cbb4ed..c423766cef14 100644
--- a/pkgs/top-level/python-packages.nix
+++ b/pkgs/top-level/python-packages.nix
@@ -717,6 +717,8 @@ in {
 
   gumath = callPackage ../development/python-modules/gumath { };
 
+  h3 = callPackage ../development/python-modules/h3 { inherit (pkgs) h3; };
+
   h5py = callPackage ../development/python-modules/h5py {
     hdf5 = pkgs.hdf5;
   };