at master 2.0 kB view raw
1{ 2 autoPatchelfHook, 3 buildPythonPackage, 4 cmake, 5 cython, 6 fetchFromGitHub, 7 h3, 8 lib, 9 ninja, 10 numpy, 11 pytestCheckHook, 12 pytest-cov-stub, 13 scikit-build-core, 14 stdenv, 15}: 16 17buildPythonPackage rec { 18 pname = "h3"; 19 version = "4.3.1"; 20 pyproject = true; 21 22 # pypi version does not include tests 23 src = fetchFromGitHub { 24 owner = "uber"; 25 repo = "h3-py"; 26 tag = "v${version}"; 27 hash = "sha256-zt7zbBgSp2P9q7mObZeQZpW9Szip62dAYdPZ2cGTmi4="; 28 }; 29 30 dontConfigure = true; 31 32 nativeCheckInputs = [ 33 pytestCheckHook 34 pytest-cov-stub 35 ]; 36 37 build-system = [ 38 scikit-build-core 39 cmake 40 cython 41 ninja 42 ] 43 ++ lib.optionals stdenv.hostPlatform.isLinux [ 44 # On Linux the .so files ends up referring to libh3.so instead of the full 45 # Nix store path. I'm not sure why this is happening! On Darwin it works 46 # fine. 47 autoPatchelfHook 48 ]; 49 50 # This is not needed per-se, it's only added for autoPatchelfHook to work 51 # correctly. See the note above ^^ 52 buildInputs = lib.optionals stdenv.hostPlatform.isLinux [ h3 ]; 53 54 dependencies = [ numpy ]; 55 56 # The following prePatch replaces the h3lib compilation with using the h3 packaged in nixpkgs. 57 # 58 # - Remove the h3lib submodule. 59 # - Patch CMakeLists to avoid building h3lib, and use h3 instead. 60 prePatch = 61 let 62 cmakeCommands = '' 63 include_directories(${lib.getDev h3}/include/h3) 64 link_directories(${h3}/lib) 65 ''; 66 in 67 '' 68 rm -r src/h3lib 69 substituteInPlace CMakeLists.txt \ 70 --replace-fail "add_subdirectory(src/h3lib)" "${cmakeCommands}" \ 71 --replace-fail "\''${CMAKE_CURRENT_BINARY_DIR}/src/h3lib/src/h3lib/include/h3api.h" "${lib.getDev h3}/include/h3/h3api.h" 72 ''; 73 74 # Extra check to make sure we can import it from Python 75 pythonImportsCheck = [ "h3" ]; 76 77 meta = { 78 homepage = "https://github.com/uber/h3-py"; 79 description = "Hierarchical hexagonal geospatial indexing system"; 80 license = lib.licenses.asl20; 81 maintainers = [ lib.maintainers.kalbasit ]; 82 }; 83}