# For more information about tox, see https://tox.readthedocs.io/en/latest/
[tox]
minversion = 4.2.3
envlist =
    lint
    pkg
    py
    py-{devel}

# do not enable skip missing to avoid CI false positives
skip_missing_interpreters = False
isolated_build = True

[testenv]
description =
    Unit testing
usedevelop = True
skip_install = False
# download assures tox gets newest pip, see https://github.com/tox-dev/tox/issues/791
download = true
# sitepackages = True
extras =
    azure
    docker
    ec2
    gce
    podman
    openstack
    test
    vagrant
deps =
    py-{devel}: git+https://github.com/ansible-community/molecule.git@main#egg=molecule[test]
commands =
    ansible-galaxy install -r requirements.yml
    pytest --collect-only
    pytest --color=yes {tty:-s}
setenv =
    ANSIBLE_FORCE_COLOR={env:ANSIBLE_FORCE_COLOR:1}
    ANSIBLE_INVENTORY={toxinidir}/tests/hosts.ini
    ANSIBLE_CONFIG={toxinidir}/ansible.cfg
    ANSIBLE_NOCOWS=1
    ANSIBLE_RETRY_FILES_ENABLED=0
    ANSIBLE_VERBOSITY={env:ANSIBLE_VERBOSITY:0}
    MOLECULE_NO_LOG={env:MOLECULE_NO_LOG:0}
    PIP_DISABLE_PIP_VERSION_CHECK=1
    PY_COLORS={env:PY_COLORS:1}
    PYTHONDONTWRITEBYTECODE=1
    # This should pass these args to molecule, no effect here as this is the default
    # but it validates that it accepts extra params.
    MOLECULE_OPTS=--destroy always
    TESTBOX={env:TESTBOX:testbox}
passenv =
    CI
    CURL_CA_BUNDLE
    DOCKER_*
    PYTEST_*
    REQUESTS_CA_BUNDLE
    SSH_AUTH_SOCK
    SSL_CERT_FILE
    TOXENV
    TWINE_*
    USER
    OS_*
allowlist_externals =
    bash
    twine
    pytest
    pre-commit

[testenv:pkg]
usedevelop = false
skip_install = true
deps =
    build >= 0.9.0
    twine >= 2.0.0
commands =
    bash -c "rm -rf {toxinidir}/dist/ && mkdir -p {toxinidir}/dist/"
    # ./build.sh
    python -m build
    twine check --strict dist/*

[testenv:lint]
description = Performs linting, style checks
allowlist_externals =
    bash
    rm
deps =
    pre-commit
    toml
commands =
    bash {toxinidir}/tools/generate-templates.sh
    pre-commit run -a
    rm -rf test/roles
