From ba3aeb1ca104f8ca7ad30766e54976f0c89736db Mon Sep 17 00:00:00 2001 From: "Wael M. Nasreddine" Date: Tue, 16 Jul 2019 17:39:52 -0700 Subject: pythonPackages.h3: init at 3.4.3 --- pkgs/development/python-modules/h3/default.nix | 35 ++++++++++++++++++ .../python-modules/h3/disable-custom-install.patch | 41 ++++++++++++++++++++++ .../python-modules/h3/hardcode-h3-path.patch | 19 ++++++++++ pkgs/top-level/python-packages.nix | 2 ++ 4 files changed, 97 insertions(+) create mode 100644 pkgs/development/python-modules/h3/default.nix create mode 100644 pkgs/development/python-modules/h3/disable-custom-install.patch create mode 100644 pkgs/development/python-modules/h3/hardcode-h3-path.patch 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; }; -- cgit 1.4.1