{% set version = '3.0.3' %}
{% set mpi = mpi or 'mpich' %}

package:
  name: mpi4py
  version: {{ version }}

source:
  - fn: mpi4py-{{ version }}.tar.gz
    url: https://github.com/mpi4py/mpi4py/releases/download/{{ version }}/mpi4py-{{ version }}.tar.gz
    sha256: 012d716c8b9ed1e513fcc4b18e5af16a8791f51e6d1716baccf988ad355c5a1f

build:
  number: 7
  script:
    - export OPAL_PREFIX=$PREFIX   # [mpi == "openmpi"]

    # On Windows, we could also just do this:
    #- set CCP_HOME=%LIBRARY_PREFIX%  # [win]
    # but conda-forge/msmpi-feedstock#1 already sets MSMPI_INC and MSMPI_LIB64,
    # so we just use them

    - {{ PYTHON }} -m pip install --no-deps . -vv
  skip: true  # [win32]

requirements:
  build:
    - python                                 # [build_platform != target_platform]
    - cross-python_{{ target_platform }}     # [build_platform != target_platform]
    - {{ compiler('c') }}
    - {{ mpi }}                              # [build_platform != target_platform and mpi == "openmpi"]
  host:
    - python
    - pip
    - {{ mpi }}
  run:
    - python
    - {{ mpi }}

test:
  commands:
    - |

    - export OMPI_MCA_plm=isolated                          # [mpi == "openmpi"]
    - export OMPI_MCA_btl_vader_single_copy_mechanism=none  # [mpi == "openmpi"]
    - export OMPI_MCA_rmaps_base_oversubscribe=yes          # [mpi == "openmpi"]
    - export OMPI_ALLOW_RUN_AS_ROOT=1                       # [mpi == "openmpi"]
    - export OMPI_ALLOW_RUN_AS_ROOT_CONFIRM=1               # [mpi == "openmpi"]

    - python -c "import mpi4py"
    - python -c "import mpi4py.MPI"
    - python -c "import mpi4py.futures"
    - python -c "from mpi4py import MPI; print(MPI.get_vendor())"  # on windows this checks MSMPI_VER
    - python -c "from mpi4py import MPI; print(MPI.Get_library_version())"
    - mpiexec -n 2 python -m mpi4py.bench helloworld
    - mpiexec -n 2 python -m mpi4py.bench ringtest

about:
  home: https://mpi4py.github.io/
  license: BSD-2-Clause
  license_family: BSD
  license_file: LICENSE.rst
  summary: Python bindings for MPI
  description: |
     MPI for Python provides bindings of the Message Passing Interface (MPI)
     standard for the Python programming language, allowing any Python program
     to exploit multiple processors.
  doc_url: https://mpi4py.readthedocs.org/
  dev_url: https://github.com/mpi4py/mpi4py

extra:
  recipe-maintainers:
    - dalcinl
    - minrk
    - msarahan
    - ocefpaf
    - davidbrochart
    - SylvainCorlay
    - leofang
