[tox]
min_version = 4
env_list =
    pre-commit,
    mypy-pkg,
    py3{8,9,10,11,12,13,14}-{tests,mypy}
    py312-bindings-main,
    pypy3-tests,
    system-argon2,
    docs-doctests,
    coverage-report


[testenv]
description = Run tests / check types and do NOT measure coverage.
package = wheel
wheel_build_env = .pkg
dependency_groups =
    tests: tests
    mypy: typing
pass_env =
    FORCE_COLOR
    NO_COLOR
commands =
    tests: pytest {posargs}
    tests: python -Im argon2 -n 1 -t 1 -m 8 -p 1
    mypy: mypy tests/typing


[testenv:py3{8,13}-tests]
description = Run tests and measure coverage.
deps =
    coverage[toml]
commands =
    coverage run -m pytest {posargs}
    coverage run -m argon2 -n 1 -t 1 -m 8 -p 1
    coverage run -m argon2 --profile CHEAPEST


[testenv:coverage-report]
description = Report coverage over all test runs.
skip_install = true
depends = py3{8,13}-tests
deps = coverage[toml]
parallel_show_output = true
commands =
    coverage combine
    coverage report


[testenv:system-argon2]
description = Run tests against bindings that use a system installation of Argon2.
set_env = ARGON2_CFFI_USE_SYSTEM=1
install_command = pip install {opts} --no-binary=argon2-cffi-bindings {packages}


[testenv:py312-bindings-main]
description = Run tests against the current main branch of argon2-cffi-bindings
dependency_groups =
deps =
commands_pre = pip install -I hypothesis pytest git+https://github.com/hynek/argon2-cffi-bindings
install_command = pip install {opts} --no-deps {packages}


[testenv:pre-commit]
description = Run all pre-commit hooks.
skip_install = true
deps = pre-commit-uv
commands = pre-commit run --all-files


[testenv:pyright]
deps = pyright
dependency_groups = typing
commands = pyright tests/typing src


[testenv:mypy-pkg]
description = Check own code.
deps = mypy
commands = mypy src


[testenv:docs-{build,doctests,linkcheck}]
# Keep base_python in sync with .readthedocs.yaml.
base_python = py313
dependency_groups = docs
commands =
    build: sphinx-build -n -T -W -b html -d {envtmpdir}/doctrees docs {posargs:docs/_build/}html
    doctests: python -m doctest README.md
    doctests: sphinx-build -n -T -W -b doctest -d {envtmpdir}/doctrees docs {posargs:docs/_build/}html
    linkcheck: sphinx-build -W -b linkcheck -d {envtmpdir}/doctrees docs docs/_build/html


[testenv:docs-watch]
package = editable
base_python = {[testenv:docs-build]base_python}
dependency_groups = {[testenv:docs-build]dependency_groups}
deps = watchfiles
commands =
    watchfiles \
        --ignore-paths docs/_build/ \
        'sphinx-build -W -n --jobs auto -b html -d {envtmpdir}/doctrees docs docs/_build/html' \
        src \
        docs \
        README.md \
        CHANGELOG.md

[testenv:docs-linkcheck]
base_python = {[testenv:docs]base_python}
dependency_groups = {[testenv:docs]dependency_groups}
commands = sphinx-build -W -b linkcheck -d {envtmpdir}/doctrees docs docs/_build/html
