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