[tox]
envlist =
    fix_lint
    py39
    py38
    py37
    py36
    py35
    py34
    py27
    pypy3
    pypy2
    coverage
    readme
    docs
isolated_build = true
skip_missing_interpreters = true
minversion = 3.14

[testenv]
description = run tests with {basepython}
passenv =
    CI_RUN
    HOME
    PIP_*
    PYTEST_*
    TERM
setenv =
    COVERAGE_FILE = {toxworkdir}/.coverage.{envname}
    COVERAGE_PROCESS_START = {toxinidir}/.coveragerc
    PYTHONIOENCODING = utf-8
    _COVERAGE_SRC = {envsitepackagesdir}/virtualenv
    {py34,py27,pypy2, upgrade}: PYTHONWARNINGS = ignore:DEPRECATION::pip._internal.cli.base_command
    {py34,pypy2,py27}: PYTEST_XDIST = 0
extras =
    testing
commands =
    python -m coverage erase
    python -m coverage run -m pytest \
      --junitxml {toxworkdir}/junit.{envname}.xml \
      {posargs:tests --int --timeout 600 -n {env:PYTEST_XDIST:auto}}
    python -m coverage combine
    python -m coverage report --skip-covered --show-missing
    python -m coverage xml -o {toxworkdir}/coverage.{envname}.xml
    python -m coverage html -d {envtmpdir}/htmlcov \
      !py34: --show-contexts \
      --title virtualenv-{envname}-coverage
install_command = python -m pip install {opts} {packages} --disable-pip-version-check

[testenv:fix_lint]
description = format the code base to adhere to our styles, and complain about what we cannot do automatically
passenv =
    *
basepython = python3.9
skip_install = true
deps =
    pre-commit>=2
commands =
    pre-commit run --all-files --show-diff-on-failure
    python -c 'import pathlib; print("hint: run \{\} install to add checks as pre-commit hook".format(pathlib.Path(r"{envdir}") / "bin" / "pre-commit"))'

[testenv:coverage]
description = [run locally after tests]: combine coverage data and create report;
    generates a diff coverage against origin/main (can be changed by setting DIFF_AGAINST env var)
passenv =
    DIFF_AGAINST
setenv =
    COVERAGE_FILE = {toxworkdir}/.coverage
skip_install = true
deps =
    coverage>=5.0.1
    diff_cover>=3
extras =
parallel_show_output = true
commands =
    python -m coverage combine
    python -m coverage report --skip-covered --show-missing
    python -m coverage xml -o {toxworkdir}/coverage.xml
    python -m coverage html -d {toxworkdir}/htmlcov
    python -m diff_cover.diff_cover_tool --compare-branch {env:DIFF_AGAINST:origin/main} {toxworkdir}/coverage.xml
depends =
    py39
    py38
    py37
    py36
    py35
    py34
    py27
    pypy
    pypy3

[testenv:readme]
description = check that the long description is valid (need for PyPI)
skip_install = true
deps =
    build>=0.0.4
    twine>=3
extras =
commands =
    python -m build -o {envtmpdir} --wheel --sdist .
    twine check {envtmpdir}/*

[testenv:docs]
description = build documentation
basepython = python3.9
extras =
    docs
commands =
    python -c 'import glob; import subprocess; subprocess.call(["proselint"] + glob.glob("docs/*.rst") + glob.glob("docs/**/*.rst"))'
    sphinx-build -d "{envtmpdir}/doctree" docs "{toxworkdir}/docs_out" --color -b html {posargs}
    python -c 'import pathlib; print("documentation available under file://\{0\}".format(pathlib.Path(r"{toxworkdir}") / "docs_out" / "index.html"))'

[testenv:upgrade]
description = upgrade pip/wheels/setuptools to latest
passenv =
    UPGRADE_ADVISORY
skip_install = true
deps =
    black
changedir = {toxinidir}/tasks
commands =
    python upgrade_wheels.py

[testenv:release]
description = do a release, required posarg of the version number
passenv =
    *
basepython = python3.9
deps =
    gitpython>=3
    packaging>=17.1
    towncrier>=19.9.0rc1
changedir = {toxinidir}/tasks
commands =
    python release.py --version {posargs}

[testenv:dev]
description = generate a DEV environment
usedevelop = true
deps =
    {[testenv:release]deps}
    setuptools_scm[toml]>=3.4
extras =
    docs
    testing
commands =
    python -m pip list --format=columns
    python -c 'import sys; print(sys.executable)'

[testenv:zipapp]
description = generate a zipapp
skip_install = true
deps =
    packaging>=20
commands =
    python tasks/make_zipapp.py

[isort]
profile = black
line_length = 120
known_first_party = virtualenv

[flake8]
max-complexity = 22
max-line-length = 120
ignore = E203, W503, C901, E402

[pep8]
max-line-length = 120
