[tox]
envlist = linters, ansible{27, 28, 29, -base}
requires =
    tox>4
    setuptools>=64

[shared]
pytest_cov_args = --cov --cov-report html --cov-report term --cov-report xml

[testenv]
description = Run tests with {basepython}
deps = ansible27: ansible<2.8
       ansible28: ansible<2.9
       ansible29: ansible<2.10
       ansible-base: ansible-base
       py{,3,39,310,311}: ansible-core
       integration{,-py39,-py310,-py311,-py312}: ansible-core
                                                 build
                                                 -r {toxinidir}/test/requirements.txt
       linters: ansible-core
passenv =
    HOME
    RUNNER_TEST_IMAGE_NAME
usedevelop = True
commands = pytest -vv -n auto {posargs}

[testenv:linters{,-py39,-py310,-py311,-py312}]
description = Run code linters
commands =
    flake8 --version
    flake8 docs src/ansible_runner test
    yamllint --version
    yamllint -s .
    mypy src/ansible_runner
    pylint src/ansible_runner test

[testenv:unit{,-py39,-py310,-py311,-py312}]
description = Run unit tests
commands =
    pytest test/unit -vv -n auto {[shared]pytest_cov_args} {posargs}

[testenv:integration{,-py39,-py310,-py311,-py312}]
description = Run integration tests
commands =
    pytest test/integration -vv -n auto {[shared]pytest_cov_args} {posargs}

[testenv:docs]
description = Build documentation
deps = -r{toxinidir}/docs/requirements.txt
commands =
    sphinx-build -T -E -W -n --keep-going {tty:--color} -j auto -d docs/build/doctrees -b html docs docs/build/html

[testenv:clean]
description = Erase docs and coverage artifacts
deps =
skip_install = True
allow_external = /bin/sh
commands =
    /bin/sh -c "rm -rf {toxinidir}/test/coverage/*"
    /bin/sh -c "rm -rf {toxinidir}/docs/{_,}build"
