[tox]
minversion = 3.14.0
envlist =
    fix_lint,
    py38,
    py37,
    py36,
    py35,
    py34,
    py27,
    pypy,
    pypy3,
    coverage,
    readme,
    docs,
isolated_build = true
skip_missing_interpreters = true

[testenv]
description = run tests with {basepython}
deps =
    pip >= 20.0.2
setenv =
    COVERAGE_FILE = {toxworkdir}/.coverage.{envname}
    COVERAGE_PROCESS_START = {toxinidir}/.coveragerc
    _COVERAGE_SRC = {envsitepackagesdir}/virtualenv
    PYTHONIOENCODING=utf-8
    PYTHONWARNINGS=ignore:DEPRECATION::pip._internal.cli.base_command
passenv = https_proxy http_proxy no_proxy HOME PYTEST_* PIP_* CI_RUN TERM
extras = testing
install_command = python -m pip install {opts} {packages} --disable-pip-version-check
commands =
    python -c 'from os.path import sep; file = open(r"{envsitepackagesdir}\{\}coverage-virtualenv.pth".format(sep), "w"); file.write("import coverage; coverage.process_startup()"); file.close()'
    coverage erase

    coverage run\
    -m pytest \
    --junitxml {toxworkdir}/junit.{envname}.xml \
    tests {posargs:--int}

    coverage combine
    coverage report

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

[testenv:docs]
basepython = python3.8
description = build documentation
extras = docs
commands =
    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:readme]
description = check that the long description is valid (need for PyPI)
deps =
    {[testenv]deps}
    twine >= 1.12.1
skip_install = true
extras =
commands =
    pip wheel -w {envtmpdir}/build --no-deps .
    twine check {envtmpdir}/build/*

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

[testenv:fix_lint]
description = format the code base to adhere to our styles, and complain about what we cannot do automatically
basepython = python3.8
passenv = *
deps = {[testenv]deps}
       pre-commit >= 2.0.0, <3
skip_install = True
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"))'

[isort]
multi_line_output = 3
include_trailing_comma = True
force_grid_wrap = 0
line_length = 120
known_standard_library = ConfigParser
known_first_party = virtualenv
known_third_party = _subprocess,appdirs,coverage,docutils,filelock,git,packaging,pytest,setuptools,six,sphinx,sphinx_rtd_theme,sphinxarg

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

[pep8]
max-line-length = 120

[testenv:dev]
description = generate a DEV environment
extras = testing, docs
usedevelop = True
deps =
    {[testenv]deps}
    docutils-stubs >= 0.0.21, <1
commands =
    python -m pip list --format=columns
    python -c 'import sys; print(sys.executable)'

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

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