[tox]
envlist = {py27,py35,py36,py37,py38}{,-cov,-diffcov},qa,docs,perf
skip_missing_interpreters = True
minversion = 3.2
# Ensure that a late version of pip is used even on tox-venv.
requires =
    tox-pip-version>=0.0.6

[testenv]
pip_version = pip
commands =
    !cov,!diffcov: python -m unittest discover {posargs}
    cov,diffcov: python -m coverage run {[coverage]rc} -m unittest discover {posargs}
    cov,diffcov: python -m coverage combine {[coverage]rc}
    cov: python -m coverage html {[coverage]rc}
    cov: python -m coverage xml {[coverage]rc}
    cov: python -m coverage report -m {[coverage]rc} --fail-under=100
    diffcov: python -m coverage xml {[coverage]rc}
    diffcov: diff-cover coverage.xml --html-report diffcov.html
    diffcov: diff-cover coverage.xml --fail-under=100
usedevelop = True
passenv =
    PYTHON*
    LANG*
    LC_*
    PYV
deps =
    cov,diffcov: coverage>=4.5
    diffcov: diff_cover
    pyfakefs
setenv =
    cov: COVERAGE_PROCESS_START={[coverage]rcfile}
    cov: COVERAGE_OPTIONS="-p"
    cov: COVERAGE_FILE={toxinidir}/.coverage
    py27: PYV=2
    py35,py36,py37,py38: PYV=3
    # workaround deprecation warnings in pip's vendored packages
    PYTHONWARNINGS=ignore:Using or importing the ABCs:DeprecationWarning:pip._vendor
extras =
    testing


[testenv:qa]
basepython = python3.7
commands =
    python -m flake8 importlib_metadata
    mypy importlib_metadata
deps =
    mypy
    flake8
    flufl.flake8
extras =


[testenv:docs]
basepython = python3
commands =
    sphinx-build docs build/sphinx/html
extras =
    docs


[testenv:perf]
use_develop = False
deps =
    ipython
commands =
    python -m timeit -s 'import importlib_metadata' -- 'importlib_metadata.distribution("ipython")'


[testenv:release]
basepython = python3
deps =
    twine
    wheel
    setuptools
    keyring
    setuptools_scm
passenv =
    TWINE_PASSWORD
setenv =
    TWINE_USERNAME = {env:TWINE_USERNAME:__token__}
commands =
    python setup.py sdist bdist_wheel
    python -m twine {posargs} upload dist/*


[coverage]
rcfile = {toxinidir}/coverage.ini
rc = --rcfile="{[coverage]rcfile}"


[flake8]
hang-closing = True
jobs = 1
max-line-length = 79
enable-extensions = U4
