[tox]
envlist =
    py,
    doc,
    sty,
passenv = PYTHONPATH
skip_install = True
skip_missing_interpreters = True
skipsdist = True

[testenv]
description =
    Run all fast unit tests and doctests
changedir = tests
allowlist_externals =
    pytest
commands =
    pytest {posargs:unittests}

[testenv:cov]
description =
    Compute the test coverage of all unit tests
changedir = tests
allowlist_externals =
    pytest
commands =
    pytest {posargs} \
        --cov-fail-under=70 \
        --cov-report=html \
        --cov-report=xml \
        --cov=pycompwa

[testenv:doc]
description =
    Build documentation and API through Sphinx
changedir = docs
passenv =
    ROOTSYS
allowlist_externals =
    make
commands =
    make html

[testenv:doclive]
description =
    Set up a server to directly preview changes to the HTML pages
changedir = .
passenv =
    EXECUTE_NB
    ROOTSYS
    TERM
allowlist_externals =
    sphinx-autobuild
commands =
    sphinx-autobuild \
        --watch docs \
        --watch src/pycompwa \
        --re-ignore .*/.ipynb_checkpoints/.* \
        --re-ignore .*/__pycache__/.* \
        --re-ignore docs/.*\.csv \
        --re-ignore docs/.*\.gv \
        --re-ignore docs/.*\.inc \
        --re-ignore docs/.*\.inv \
        --re-ignore docs/.*\.json \
        --re-ignore docs/.*\.pickle \
        --re-ignore docs/.*\.yaml \
        --re-ignore docs/.*\.yml \
        --re-ignore docs/_build/.* \
        --re-ignore docs/api/.* \
        --open-browser \
        docs/ docs/_build/html

[testenv:docnb]
description =
    Build documentation through Sphinx WITH output of Jupyter notebooks
changedir = docs
passenv =
    ROOTSYS
setenv =
    EXECUTE_NB = "yes"
allowlist_externals =
    make
commands =
    make html

[testenv:linkcheck]
description =
    Check external links in the documentation (requires internet connection)
changedir = docs
allowlist_externals =
    make
commands =
    make ignore-warnings=1 linkcheck # for margin directive

[testenv:sty]
description =
    Perform all linting, formatting, and spelling checks
passenv =
    SKIP
setenv =
    SKIP = flake8, pylint
allowlist_externals =
    pre-commit
commands =
    pre-commit run {posargs} -a
