[tox]
env_list =
    codestyle
    test-xdist
    build-{dist, docs}
isolated_build = true

[testenv:codestyle]
description = check code style with ruff
change_dir = .
skip_install = true
deps = 
    ruff
commands = 
    ruff .

[testenv]
# tox environments are constructed with so-called 'factors' (or terms)
# separated by hyphens, e.g. test-devdeps-cov. Lines below starting with factor:
# will only take effect if that factor is included in the environment name. To
# see a list of example environments that can be run, along with a description,
# run:
#
#     tox -l -v
#
description =
    run tests
    oldestdeps: with the oldest supported version of key dependencies
    cov: and test coverage
    xdist: in parallel

# Pass through the following environment variables which may be needed for the CI
pass_env = 
    HOME
    WINDIR
    LC_ALL
    LC_CTYPE
    CC
    CI
    TRAVIS

# Suppress display of matplotlib plots generated during docs build
set_env = 
    MPLBACKEND=agg

# Run the tests in a temporary directory to make sure that we don't import
# the package from the source tree
change_dir = .tmp/{envname}

deps = 
    cov: pytest-cov
    oldestdeps: minimum_dependencies
    xdist: pytest-xdist

# The following indicates which extras_require from setup.cfg will be installed
extras =
    test

commands_pre =
    oldestdeps: minimum_dependencies packagename --filename requirements-min.txt
    oldestdeps: pip install -r requirements-min.txt
    pip freeze

commands =
    pytest --pyargs corona_lab {toxinidir}/docs {posargs}
    cov: pytest --pyargs corona_lab {toxinidir}/docs --cov corona_lab --cov-report xml:coverage.xml --cov-report term-missing {posargs}
    xdist: pytest --pyargs corona_lab {toxinidir}/docs --cov corona_lab --cov-report xml:coverage.xml --cov-report term-missing -n auto {posargs}
    

[testenv:check-build]
description = check PEP517 package build
change_dir = .
skip_install = true
deps =
    build
    twine
commands =
    python -m build --sdist .
    twine check dist/*

[testenv:build-docs]
change_dir = docs
description = invoke sphinx-build to build the HTML docs
extras = 
    docs
commands =
    sphinx-build -W . _build {posargs}
