1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 cython,
6 setuptools,
7 mpi,
8 toPythonModule,
9 pytest,
10 mpiCheckPhaseHook,
11 mpi4py,
12 mpich,
13}:
14
15buildPythonPackage rec {
16 pname = "mpi4py";
17 version = "4.1.0";
18 pyproject = true;
19
20 src = fetchFromGitHub {
21 repo = "mpi4py";
22 owner = "mpi4py";
23 tag = version;
24 hash = "sha256-Hm+x79utOrjAbprud2MECgakyOzgShSwNuoyZUcTluQ=";
25 };
26
27 build-system = [
28 cython
29 setuptools
30 ];
31
32 nativeBuildInputs = [
33 mpi
34 ];
35
36 dependencies = [
37 # Use toPythonModule so that also the mpi executables will be propagated to
38 # generated Python environment.
39 (toPythonModule mpi)
40 ];
41
42 pythonImportsCheck = [ "mpi4py" ];
43
44 nativeCheckInputs = [
45 pytest
46 mpiCheckPhaseHook
47 ];
48
49 __darwinAllowLocalNetworking = true;
50
51 # skip spawn related tests for openmpi implemention
52 # see https://github.com/mpi4py/mpi4py/issues/545#issuecomment-2343011460
53 env.MPI4PY_TEST_SPAWN = if mpi.pname == "openmpi" then 0 else 1;
54
55 # follow upstream's checkPhase
56 # see https://github.com/mpi4py/mpi4py/blob/4.1.0/.github/workflows/ci-test.yml#L92-L95
57 checkPhase = ''
58 runHook preCheck
59
60 echo 'Testing mpi4py (np=1)'
61 mpiexec -n 1 python test/main.py -v
62 echo 'Testing mpi4py (np=2)'
63 mpiexec -n 2 python test/main.py -v -f -e spawn
64
65 runHook postCheck
66 '';
67
68 passthru = {
69 inherit mpi;
70
71 tests = {
72 mpich = mpi4py.override { mpi = mpich; };
73 };
74 };
75
76 meta = {
77 description = "Python bindings for the Message Passing Interface standard";
78 homepage = "https://github.com/mpi4py/mpi4py";
79 changelog = "https://github.com/mpi4py/mpi4py/blob/${src.tag}/CHANGES.rst";
80 license = lib.licenses.bsd2;
81 maintainers = with lib.maintainers; [ doronbehar ];
82 };
83}