Files
nixpkgs/pkgs/development/python-modules/dm-tree/default.nix
whispers 4577918a59 python3Packages.dm-tree: fix build with __structuredAttrs
__structuredAttrs is now enabled by default for python packages. this
means that the current way of passing cmakeFlags, by interpreting it as
string in the environment variable, no longer works; it now becomes a
regular bash array. to work around this, we expand it directly in nix.

the other alternative i can think of is using
'import json; cmake_args = json.load(open(os.environ["NIX_ATTRS_JSON_FILE"])).get("cmakeFlags", []) + ['
but i'm not sure that's much better either.
2026-10-12 18:10:31 -04:00

80 lines
1.6 KiB
Nix

{
lib,
buildPythonPackage,
fetchFromGitHub,
# nativeBuildInputs
cmake,
pybind11,
# buildInputs
abseil-cpp,
# build-system
setuptools,
# dependencies
absl-py,
attrs,
numpy,
wrapt,
}:
buildPythonPackage (finalAttrs: {
pname = "dm-tree";
version = "0.1.10";
pyproject = true;
src = fetchFromGitHub {
owner = "deepmind";
repo = "tree";
tag = finalAttrs.version;
hash = "sha256-L1DOwgJriFoS0rf6g+f3qcw94Q/ia4N6kZ1ai6F/Qng=";
};
# Allows to forward cmake args through the conventional `cmakeFlags`
postPatch = ''
substituteInPlace setup.py \
--replace-fail \
"cmake_args = [" \
"cmake_args = [ *\"''${cmakeFlags[*]}\".split(),"
'';
cmakeFlags = [
(lib.cmakeBool "USE_SYSTEM_ABSEIL" true)
(lib.cmakeBool "USE_SYSTEM_PYBIND11" true)
];
dontUseCmakeConfigure = true;
nativeBuildInputs = [
cmake
pybind11
];
buildInputs = [
abseil-cpp
pybind11
];
build-system = [ setuptools ];
# It is unclear whether those are runtime dependencies or simply test dependencies
# https://github.com/google-deepmind/tree/issues/127
dependencies = [
absl-py
attrs
numpy
wrapt
];
pythonImportsCheck = [ "tree" ];
meta = {
description = "Python library for working with nested data structures";
homepage = "https://github.com/deepmind/tree";
changelog = "https://github.com/google-deepmind/tree/releases/tag/${finalAttrs.src.tag}";
license = lib.licenses.asl20;
maintainers = with lib.maintainers; [
samuela
ndl
];
};
})