[tox]
minversion = 4.0.0
envlist =
    lint
    py
    pkg
isolated_build = True

[testenv]
setenv =
    PYTHONWARNINGS=error::FutureWarning
    # Aim to replace with below once other issues are fixed:
    # PYTHONWARNINGS=error
    COVERAGE_FILE = {env:COVERAGE_FILE:{toxworkdir}/.coverage.{envname}}
deps =
    pytest
    pytest-cov
sitepackages = False
usedevelop = True
commands = python -m pytest -ra --cov=src/ --no-cov-on-fail --cov-append --cov-report=xml:{toxworkdir}/coverage-{envname}.xml

[testenv:lint]
description = Runs all linting tasks
commands =
    # to run a single linter you can do "pre-commit run flake8"
    python -m pre_commit run {posargs:--all}
deps = pre-commit>=1.18.1
extras =
skip_install = true
usedevelop = false

[testenv:pkg]
description =
    Do packaging/distribution. If tag is not present or PEP440 compliant upload to
    PYPI could fail
# `usedevelop = true` overrides `skip_install` instruction, it's unwanted
usedevelop = false
# don't install molecule itself in this env
skip_install = true
deps =
    asciidoc >= 10.1.4
    collective.checkdocs >= 0.2
    build >= 0.7.0
    pip >= 20.2.2
    setuptools_scm >= 6.0.1
    toml >= 0.10.1
    twine >= 3.2.0  # pyup: ignore
setenv =
commands =
    rm -rfv {toxinidir}/dist/
    python -m build \
      --outdir {toxinidir}/dist/ \
      {toxinidir}
    # metadata validation
    sh -c "python -m twine check --strict {toxinidir}/dist/*"
allowlist_externals =
    rm
    sh

[testenv:docs]
description = Generate Sphinx docs under build/docs
extras = docs
commands =
    # Disabled due https://github.com/pycontribs/ansi2html/issues/193
    ; sh -c 'a2x \
    ;   --verbose \
    ;   --no-xmllint \
    ;   --conf-file=man/asciidoc.conf \
    ;   --attribute="manual_package=ansi2html" \
    ;   --attribute="manual_title=ansi2html Manual" \
    ;   --attribute="manual_version=$(python3 -m setuptools_scm)" \
    ;   --format=manpage -D man \
    ;   man/ansi2html.1.txt'
    mkdocs {posargs:build --strict --site-dir=_readthedocs/html/}
