[tox]
isolated_build = True
minversion = 3.20.0
distshare = {homedir}/.tox/distshare
envlist =
    linting
    py38
    py39
    py310
    py311
    py312
    py313
    pypy3
    py38-{pexpect,xdist,unittestextras,numpy,pluggymain,pylib}
    doctesting
    doctesting-coverage
    plugins
    py38-freeze
    docs
    docs-checklinks

    # checks that 3.11 native ExceptionGroup works with exceptiongroup
    # not included in CI.
    py311-exceptiongroup



[testenv]
commands =
    {env:_PYTEST_TOX_COVERAGE_RUN:} pytest {posargs:{env:_PYTEST_TOX_DEFAULT_POSARGS:}}
    doctesting: {env:_PYTEST_TOX_COVERAGE_RUN:} pytest --doctest-modules --pyargs _pytest
    coverage: coverage combine
    coverage: coverage report -m
passenv =
    COVERAGE_*
    PYTEST_ADDOPTS
    TERM
    SETUPTOOLS_SCM_PRETEND_VERSION_FOR_PYTEST
setenv =
    _PYTEST_TOX_DEFAULT_POSARGS={env:_PYTEST_TOX_POSARGS_DOCTESTING:} {env:_PYTEST_TOX_POSARGS_LSOF:} {env:_PYTEST_TOX_POSARGS_XDIST:}

    # See https://docs.python.org/3/library/io.html#io-encoding-warning
    # If we don't enable this, neither can any of our downstream users!
    PYTHONWARNDEFAULTENCODING=1

    # Configuration to run with coverage similar to CI, e.g.
    # "tox -e py38-coverage".
    coverage: _PYTEST_TOX_COVERAGE_RUN=coverage run -m
    coverage: _PYTEST_TOX_EXTRA_DEP=coverage-enable-subprocess
    coverage: COVERAGE_FILE={toxinidir}/.coverage
    coverage: COVERAGE_PROCESS_START={toxinidir}/.coveragerc

    doctesting: _PYTEST_TOX_POSARGS_DOCTESTING=doc/en

    nobyte: PYTHONDONTWRITEBYTECODE=1

    lsof: _PYTEST_TOX_POSARGS_LSOF=--lsof

    xdist: _PYTEST_TOX_POSARGS_XDIST=-n auto
extras = dev
deps =
    doctesting: PyYAML
    exceptiongroup: exceptiongroup>=1.0.0rc8
    numpy: numpy>=1.19.4
    pexpect: pexpect>=4.8.0
    pluggymain: pluggy @ git+https://github.com/pytest-dev/pluggy.git
    pylib: py>=1.8.2
    unittestextras: twisted
    unittestextras: asynctest
    xdist: pytest-xdist>=2.1.0
    xdist: -e .
    {env:_PYTEST_TOX_EXTRA_DEP:}

[testenv:linting]
skip_install = True
basepython = python3
deps = pre-commit>=2.9.3
commands = pre-commit run --all-files --show-diff-on-failure {posargs:}
setenv =
    # pre-commit and tools it launches are not clean of this warning.
    PYTHONWARNDEFAULTENCODING=

[testenv:docs]
basepython = python3
usedevelop = True
deps =
    -r{toxinidir}/doc/en/requirements.txt
    # https://github.com/twisted/towncrier/issues/340
    towncrier<21.3.0
commands =
    python scripts/towncrier-draft-to-file.py
    # the '-t changelog_towncrier_draft' tags makes sphinx include the draft
    # changelog in the docs; this does not happen on ReadTheDocs because it uses
    # the standard sphinx command so the 'changelog_towncrier_draft' is never set there
    sphinx-build -W --keep-going -b html doc/en doc/en/_build/html -t changelog_towncrier_draft {posargs:}
setenv =
    # Sphinx is not clean of this warning.
    PYTHONWARNDEFAULTENCODING=

[testenv:docs-checklinks]
basepython = python3
usedevelop = True
changedir = doc/en
deps = -r{toxinidir}/doc/en/requirements.txt
commands =
    sphinx-build -W -q --keep-going -b linkcheck . _build
setenv =
    # Sphinx is not clean of this warning.
    PYTHONWARNDEFAULTENCODING=

[testenv:regen]
changedir = doc/en
basepython = python3
passenv =
    SETUPTOOLS_SCM_PRETEND_VERSION_FOR_PYTEST
deps =
    PyYAML
    regendoc>=0.8.1
    sphinx
allowlist_externals =
    make
commands =
    make regen
setenv =
    # We don't want this warning to reach regen output.
    PYTHONWARNDEFAULTENCODING=

[testenv:plugins]
# use latest versions of all plugins, including pre-releases
pip_pre=true
# use latest pip to get new dependency resolver (#7783)
download=true
install_command=python -m pip install {opts} {packages}
changedir = testing/plugins_integration
deps = -rtesting/plugins_integration/requirements.txt
setenv =
    PYTHONPATH=.
# Command temporarily removed until pytest-bdd is fixed:
# https://github.com/pytest-dev/pytest/pull/11785
# pytest bdd_wallet.py
commands =
    pip check
    pytest --cov=. simple_integration.py
    pytest --ds=django_settings simple_integration.py
    pytest --html=simple.html simple_integration.py
    pytest --reruns 5 simple_integration.py
    pytest pytest_anyio_integration.py
    pytest pytest_asyncio_integration.py
    pytest pytest_mock_integration.py
    pytest pytest_trio_integration.py
    pytest pytest_twisted_integration.py
    pytest simple_integration.py --force-sugar --flakes

[testenv:py38-freeze]
changedir = testing/freeze
deps =
    pyinstaller
commands =
    {envpython} create_executable.py
    {envpython} tox_run.py

[testenv:release]
description = do a release, required posarg of the version number
basepython = python3
usedevelop = True
passenv = *
deps =
    colorama
    github3.py
    pre-commit>=2.9.3
    wheel
    # https://github.com/twisted/towncrier/issues/340
    towncrier<21.3.0
commands = python scripts/release.py {posargs}

[testenv:prepare-release-pr]
description = prepare a release PR from a manual trigger in GitHub actions
usedevelop = {[testenv:release]usedevelop}
passenv = {[testenv:release]passenv}
deps = {[testenv:release]deps}
commands = python scripts/prepare-release-pr.py {posargs}

[testenv:generate-gh-release-notes]
description = generate release notes that can be published as GitHub Release
basepython = python3
usedevelop = True
deps =
    pypandoc
commands = python scripts/generate-gh-release-notes.py {posargs}
