# Tox (https://tox.readthedocs.io) is a tool for running tests
# in multiple virtualenvs. This configuration file will run the
# test suite on all supported python versions. To use it,
# "pip install tox" and then run "tox" from this directory.

[tox]
minversion = 3.8.0
skip_missing_interpreters=True
envlist =
    py27,
    py35,
    py36,
    py37,
    py38,
    py39,
    py310,
    pypy2,
    pypy3,

[mpi]
mpiexec = {env:MPIEXEC:mpiexec}

[testenv]
deps = numpy
whitelist_externals = {[mpi]mpiexec}
commands =
    {[mpi]mpiexec} -n 1 {envpython} -m mpi4py --version
    {[mpi]mpiexec} -n 5 {envpython} -m mpi4py -m mpi4py.bench helloworld
    {[mpi]mpiexec} -n 5 {envpython} -m mpi4py -m mpi4py.bench ringtest
    {[mpi]mpiexec} -n 1 {envpython} {toxinidir}/test/runtests.py --no-builddir -q -e spawn []
    {[mpi]mpiexec} -n 5 {envpython} {toxinidir}/test/runtests.py --no-builddir -q -e spawn []
    {[mpi]mpiexec} -n 1 {envpython} -m mpi4py.futures {toxinidir}/demo/futures/test_futures.py -q []
    {[mpi]mpiexec} -n 5 {envpython} -m mpi4py.futures {toxinidir}/demo/futures/test_futures.py -q []

[testenv:lint]
deps =
    pycodestyle
    pydocstyle
    flake8
    pylint
    mypy
commands =
    pycodestyle {toxinidir}/src/mpi4py
    pydocstyle {toxinidir}/src/mpi4py
    flake8 {toxinidir}/src/mpi4py
    pylint mpi4py
    stubtest mpi4py \
      --mypy-config-file={toxinidir}/conf/mypy.ini \
      --allowlist={toxinidir}/conf/mypy.stubtest.allow.txt
    mypy -p mpi4py \
      --config-file={toxinidir}/conf/mypy.ini

[cmd]
rst2html5 = rst2html5.py --config=conf/docutils.conf

[testenv:docs]
deps =
    sphinx
whitelist_externals =
    rm
    mv
setenv =
    MPICFG=nompi
    CFLAGS=-O0
    TOPDIR=
    DOCDIR=docs/
    SRCDIR=docs/source/usrman/
    BLDDIR=build/
    OUTDIR=docs/
    LATEXMKOPTS=-quiet
commands_pre =
    rm -rf {env:OUTDIR}usrman
commands =
    {[cmd]rst2html5} {env:TOPDIR}LICENSE.rst {env:OUTDIR}LICENSE.html
    {[cmd]rst2html5} {env:TOPDIR}CHANGES.rst {env:OUTDIR}CHANGES.html
    {[cmd]rst2html5} {env:DOCDIR}index.rst   {env:OUTDIR}index.html
    sphinx-build -M html     {env:SRCDIR} {env:BLDDIR} -q -W -j auto
    sphinx-build -M man      {env:SRCDIR} {env:BLDDIR} -q -W -j auto
    sphinx-build -M info     {env:SRCDIR} {env:BLDDIR} -q -W -j auto
    sphinx-build -M latexpdf {env:SRCDIR} {env:BLDDIR} -q -W -j auto
    rm {env:BLDDIR}html/.buildinfo
    mv {env:BLDDIR}html                {env:OUTDIR}usrman
    mv {env:BLDDIR}man/mpi4py.1        {env:OUTDIR}
    mv {env:BLDDIR}texinfo/mpi4py.info {env:OUTDIR}
    mv {env:BLDDIR}latex/mpi4py.pdf    {env:OUTDIR}

[testenv:epydoc]
basepython = python2.7
deps =
    epydoc
    docutils
whitelist_externals = rm
setenv =
    MPICFG=nompi
    CFLAGS=-O0
commands_pre =
    rm -rf docs/apiref
commands =
    {envpython} ./conf/epydocify.py --html -o docs/apiref

[testenv:sdist]
deps =
skip_install = true
depends =
    docs
    epydoc
whitelist_externals = test
commands_pre =
    test -f docs/LICENSE.html
    test -f docs/CHANGES.html
    test -f docs/index.html
    test -d docs/usrman
    test -f docs/mpi4py.1
    test -f docs/mpi4py.info
    test -f docs/mpi4py.pdf
    test -d docs/apiref
commands =
    {envpython} setup.py -q sdist
