summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/mpi4py/default.nix
blob: b95bb5d0142ef0f86d98bf7ebee3db0d453dcf60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
{
  lib,
  buildPythonPackage,
  fetchFromGitHub,
  cython,
  setuptools,
  mpi,
  toPythonModule,
  pytest,
  mpiCheckPhaseHook,
  mpi4py,
  mpich,
}:

buildPythonPackage rec {
  pname = "mpi4py";
  version = "4.1.1";
  pyproject = true;

  src = fetchFromGitHub {
    repo = "mpi4py";
    owner = "mpi4py";
    tag = version;
    hash = "sha256-I7b4x3pxtfbmlbno5OIxo4HutRX3/RjdsoNtBRKgE5w=";
  };

  build-system = [
    cython
    setuptools
  ];

  nativeBuildInputs = [
    mpi
  ];

  dependencies = [
    # Use toPythonModule so that also the mpi executables will be propagated to
    # generated Python environment.
    (toPythonModule mpi)
  ];

  pythonImportsCheck = [ "mpi4py" ];

  nativeCheckInputs = [
    pytest
    mpiCheckPhaseHook
  ];

  __darwinAllowLocalNetworking = true;

  # skip spawn related tests for openmpi implemention
  # see https://github.com/mpi4py/mpi4py/issues/545#issuecomment-2343011460
  env.MPI4PY_TEST_SPAWN = if mpi.pname == "openmpi" then 0 else 1;

  # follow upstream's checkPhase
  # see https://github.com/mpi4py/mpi4py/blob/4.1.0/.github/workflows/ci-test.yml#L92-L95
  checkPhase = ''
    runHook preCheck

    echo 'Testing mpi4py (np=1)'
    mpiexec -n 1 python test/main.py -v
    echo 'Testing mpi4py (np=2)'
    mpiexec -n 2 python test/main.py -v -f -e spawn

    runHook postCheck
  '';

  passthru = {
    inherit mpi;

    tests = {
      mpich = mpi4py.override { mpi = mpich; };
    };
  };

  meta = {
    description = "Python bindings for the Message Passing Interface standard";
    homepage = "https://github.com/mpi4py/mpi4py";
    changelog = "https://github.com/mpi4py/mpi4py/blob/${src.tag}/CHANGES.rst";
    license = lib.licenses.bsd2;
    maintainers = with lib.maintainers; [ doronbehar ];
  };
}