2024-06-05 15:53:02 +00:00
|
|
|
{
|
|
|
|
autoPatchelfHook,
|
|
|
|
buildPythonPackage,
|
|
|
|
cmake,
|
|
|
|
cython,
|
|
|
|
fetchFromGitHub,
|
|
|
|
h3,
|
|
|
|
lib,
|
|
|
|
numpy,
|
|
|
|
pytestCheckHook,
|
|
|
|
scikit-build,
|
|
|
|
stdenv,
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
buildPythonPackage rec {
|
|
|
|
pname = "h3";
|
2024-04-21 15:54:59 +00:00
|
|
|
version = "3.7.7";
|
2024-01-02 11:29:13 +00:00
|
|
|
format = "setuptools";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-02-13 14:23:35 +00:00
|
|
|
# pypi version does not include tests
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "uber";
|
|
|
|
repo = "h3-py";
|
2022-04-27 09:35:20 +00:00
|
|
|
rev = "refs/tags/v${version}";
|
2024-04-21 15:54:59 +00:00
|
|
|
hash = "sha256-wXQaSMXQI0f7zfyj37mubxdqGFv7vhHQd6rH08H57d4=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2021-02-13 14:23:35 +00:00
|
|
|
dontConfigure = true;
|
|
|
|
|
2023-02-02 18:25:31 +00:00
|
|
|
nativeCheckInputs = [ pytestCheckHook ];
|
2021-02-13 14:23:35 +00:00
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
nativeBuildInputs =
|
|
|
|
[
|
|
|
|
scikit-build
|
|
|
|
cmake
|
|
|
|
cython
|
|
|
|
]
|
|
|
|
++ lib.optionals stdenv.hostPlatform.isLinux [
|
|
|
|
# On Linux the .so files ends up referring to libh3.so instead of the full
|
|
|
|
# Nix store path. I'm not sure why this is happening! On Darwin it works
|
|
|
|
# fine.
|
|
|
|
autoPatchelfHook
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-02-13 14:23:35 +00:00
|
|
|
# This is not needed per-se, it's only added for autoPatchelfHook to work
|
|
|
|
# correctly. See the note above ^^
|
|
|
|
buildInputs = lib.optionals stdenv.hostPlatform.isLinux [ h3 ];
|
|
|
|
|
|
|
|
propagatedBuildInputs = [ numpy ];
|
|
|
|
|
|
|
|
# The following prePatch replaces the h3lib compilation with using the h3 packaged in nixpkgs.
|
|
|
|
#
|
|
|
|
# - Remove the h3lib submodule.
|
|
|
|
# - Patch CMakeLists to avoid building h3lib, and use h3 instead.
|
|
|
|
prePatch =
|
|
|
|
let
|
|
|
|
cmakeCommands = ''
|
2024-01-02 11:29:13 +00:00
|
|
|
include_directories(${lib.getDev h3}/include/h3)
|
2021-02-13 14:23:35 +00:00
|
|
|
link_directories(${h3}/lib)
|
|
|
|
'';
|
2024-06-05 15:53:02 +00:00
|
|
|
in
|
|
|
|
''
|
2021-02-13 14:23:35 +00:00
|
|
|
rm -r src/h3lib
|
|
|
|
substituteInPlace CMakeLists.txt --replace "add_subdirectory(src/h3lib)" "${cmakeCommands}"
|
|
|
|
'';
|
|
|
|
|
|
|
|
# Extra check to make sure we can import it from Python
|
|
|
|
pythonImportsCheck = [ "h3" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
homepage = "https://github.com/uber/h3-py";
|
2021-02-13 14:23:35 +00:00
|
|
|
description = "Hierarchical hexagonal geospatial indexing system";
|
2020-04-24 23:36:52 +00:00
|
|
|
license = licenses.asl20;
|
|
|
|
maintainers = [ maintainers.kalbasit ];
|
|
|
|
};
|
|
|
|
}
|