at 25.11-pre 2.1 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.2.2"; 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-HvJT5SuE7UHhGMlaQG3YSHfGkgsdDAVVGsGRsAeNHGQ="; 28 }; 29 30 dontConfigure = true; 31 32 nativeCheckInputs = [ 33 pytestCheckHook 34 pytest-cov-stub 35 ]; 36 37 build-system = 38 [ 39 scikit-build-core 40 cmake 41 cython 42 ninja 43 ] 44 ++ lib.optionals stdenv.hostPlatform.isLinux [ 45 # On Linux the .so files ends up referring to libh3.so instead of the full 46 # Nix store path. I'm not sure why this is happening! On Darwin it works 47 # fine. 48 autoPatchelfHook 49 ]; 50 51 # This is not needed per-se, it's only added for autoPatchelfHook to work 52 # correctly. See the note above ^^ 53 buildInputs = lib.optionals stdenv.hostPlatform.isLinux [ h3 ]; 54 55 dependencies = [ numpy ]; 56 57 # The following prePatch replaces the h3lib compilation with using the h3 packaged in nixpkgs. 58 # 59 # - Remove the h3lib submodule. 60 # - Patch CMakeLists to avoid building h3lib, and use h3 instead. 61 prePatch = 62 let 63 cmakeCommands = '' 64 include_directories(${lib.getDev h3}/include/h3) 65 link_directories(${h3}/lib) 66 ''; 67 in 68 '' 69 rm -r src/h3lib 70 substituteInPlace CMakeLists.txt \ 71 --replace-fail "add_subdirectory(src/h3lib)" "${cmakeCommands}" \ 72 --replace-fail "\''${CMAKE_CURRENT_BINARY_DIR}/src/h3lib/src/h3lib/include/h3api.h" "${lib.getDev h3}/include/h3/h3api.h" 73 ''; 74 75 # Extra check to make sure we can import it from Python 76 pythonImportsCheck = [ "h3" ]; 77 78 meta = { 79 homepage = "https://github.com/uber/h3-py"; 80 description = "Hierarchical hexagonal geospatial indexing system"; 81 license = lib.licenses.asl20; 82 maintainers = [ lib.maintainers.kalbasit ]; 83 }; 84}