1{
2 lib,
3 fetchPypi,
4 buildPythonPackage,
5 pythonOlder,
6 setuptools,
7 numpy,
8 hdf5,
9 cython,
10 pkgconfig,
11 mpi4py ? null,
12 openssh,
13 pytestCheckHook,
14 pytest-mpi,
15 cached-property,
16}:
17
18assert hdf5.mpiSupport -> mpi4py != null && hdf5.mpi == mpi4py.mpi;
19
20let
21 mpi = hdf5.mpi;
22 mpiSupport = hdf5.mpiSupport;
23in
24buildPythonPackage rec {
25 version = "3.13.0";
26 pname = "h5py";
27 pyproject = true;
28
29 disabled = pythonOlder "3.7";
30
31 src = fetchPypi {
32 inherit pname version;
33 hash = "sha256-GHDkZRhyACPahdCJWhlg/yzjmMVnHqw7GkHsaWtxBcM=";
34 };
35
36 pythonRelaxDeps = [ "mpi4py" ];
37
38 # Avoid strict pinning of Numpy, can't be replaced with pythonRelaxDepsHook,
39 # as these are build time dependencies. See:
40 # https://github.com/NixOS/nixpkgs/issues/327941
41 postPatch = ''
42 substituteInPlace pyproject.toml \
43 --replace-fail "numpy >=2.0.0, <3" "numpy"
44 '';
45
46 env = {
47 HDF5_DIR = "${hdf5}";
48 HDF5_MPI = if mpiSupport then "ON" else "OFF";
49 # See discussion at https://github.com/h5py/h5py/issues/2560
50 H5PY_SETUP_REQUIRES = 0;
51 };
52
53 postConfigure = ''
54 # Needed to run the tests reliably. See:
55 # https://bitbucket.org/mpi4py/mpi4py/issues/87/multiple-test-errors-with-openmpi-30
56 ${lib.optionalString mpiSupport "export OMPI_MCA_rmaps_base_oversubscribe=yes"}
57 '';
58
59 preBuild = lib.optionalString mpiSupport "export CC=${lib.getDev mpi}/bin/mpicc";
60
61 build-system = [
62 cython
63 numpy
64 pkgconfig
65 setuptools
66 ];
67
68 buildInputs = [ hdf5 ] ++ lib.optional mpiSupport mpi;
69
70 dependencies =
71 [ numpy ]
72 ++ lib.optionals mpiSupport [
73 mpi4py
74 openssh
75 ]
76 ++ lib.optionals (pythonOlder "3.8") [ cached-property ];
77
78 nativeCheckInputs = [
79 pytestCheckHook
80 pytest-mpi
81 openssh
82 ];
83 # https://github.com/NixOS/nixpkgs/issues/255262
84 preCheck = ''
85 cd $out
86 '';
87 # For some reason these fail when mpi support is enabled, due to concurrent
88 # writings. There are a few open issues about this in the bug tracker, but
89 # not related to the tests.
90 disabledTests = lib.optionals mpiSupport [ "TestPageBuffering" ];
91
92 pythonImportsCheck = [ "h5py" ];
93
94 meta = {
95 changelog = "https://github.com/h5py/h5py/blob/${version}/docs/whatsnew/${lib.versions.majorMinor version}.rst";
96 description = "Pythonic interface to the HDF5 binary data format";
97 homepage = "http://www.h5py.org/";
98 license = lib.licenses.bsd3;
99 maintainers = with lib.maintainers; [ doronbehar ];
100 };
101}