[tox]
envlist =
    py310
    py311
    py312
    py313
    py314
    py315
    docs
    docs-demos
    docs-linkcheck
    readme
    ruff
    codespell
; mypy is intentionally excluded: 11 non-gating precision errors are
; documented (see PR 4); it stays a local-only convenience env.
skip_missing_interpreters = True

[testenv]
deps =
    -r{toxinidir}/tests/requirements.txt
    pyright
commands =
    pyright
    py.test --cov progressbar --cov-report=html --cov-report=term-missing --cov-report=xml --cov-config=./pyproject.toml --no-cov-on-fail --basetemp="{envtmpdir}" --confcutdir=.. {posargs}
skip_install = true

[testenv:mypy]
changedir =
basepython = python3
deps = mypy
commands = mypy {toxinidir}/progressbar

[testenv:docs]
changedir =
basepython = python3
deps =
    -r{toxinidir}/docs/requirements.txt
    build
allowlist_externals =
    rm
    mkdir
commands =
    rm -f docs/modules.rst
    mkdir -p docs/_static
    python scripts/build_docs_wheels.py
    sphinx-apidoc -e -o docs/ progressbar */os_specific/* */six.py
    rm -f docs/modules.rst
    sphinx-build -W -b html -d docs/_build/doctrees docs docs/_build/html {posargs}

[testenv:docs-demos]
changedir =
basepython = python3
deps = -r{toxinidir}/tests/requirements.txt
commands =
    python scripts/render_demos.py --check
    python scripts/render_race.py --check

; Guards the PyPI project page: builds the sdist and runs twine's
; readme_renderer check over it, so a README change that PyPI would
; refuse or silently strip fails CI instead of shipping a broken page.
[testenv:readme]
changedir =
basepython = python3
skip_install = true
deps =
    build
    twine
    ; twine bundles readme_renderer, but Markdown rendering is an extra:
    ; without it the long-description check cannot actually render the
    ; README and the gate would pass vacuously.
    readme_renderer[md]
commands =
    python -m build --sdist --outdir {envtmpdir}/dist
    twine check --strict {envtmpdir}/dist/*

[testenv:docs-linkcheck]
changedir =
basepython = python3
deps = -r{toxinidir}/docs/requirements.txt
commands =
    sphinx-build -b linkcheck -d docs/_build/doctrees docs docs/_build/linkcheck

[testenv:ruff]
commands =
    ruff check
    ruff format --check
deps = ruff
skip_install = true

[testenv:codespell]
changedir = {toxinidir}
commands = codespell .
deps = codespell
skip_install = true