[tox]
envlist = py3,pep8,cover,api-ref,releasenotes,bandit,fakemodetests
minversion = 3.18.0

[testenv]
setenv = VIRTUAL_ENV={envdir}
         PYTHONWARNINGS=default::DeprecationWarning
         OS_TEST_PATH=./trove/tests/unittests
         OS_STDOUT_CAPTURE=1
         OS_STDERR_CAPTURE=1

usedevelop = True
install_command = pip install \
                  -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master} \
                  -U {opts} {packages}
deps = -r{toxinidir}/requirements.txt
       -r{toxinidir}/test-requirements.txt
commands = find ./trove -type f -name "*.pyc" -delete
           rm -f trove_test.sqlite
           stestr run --serial {posargs}
           stestr slowest
allowlist_externals = find
                      rm
                      bash

[testenv:pep8]
deps =
  -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
  -r{toxinidir}/test-requirements.txt
  -r{toxinidir}/doc/requirements.txt
commands =
    flake8
    reno lint
    doc8 {posargs}
    doc8 -e '.yaml' releasenotes/notes/
    doc8 doc/source

[testenv:debug]
commands = oslo_debug_helper {posargs}

[testenv:cover]
allowlist_externals = sh
                      rm
setenv =
  {[testenv]setenv}
  PYTHON=coverage run --source trove
commands =
     rm -f trove_test.sqlite
     coverage erase
     sh -c 'OS_TEST_PATH={toxinidir}/backup/tests/unittests stestr run --serial {posargs}'
     sh -c 'OS_TEST_PATH={toxinidir}/trove/tests/unittests stestr run --serial {posargs}'
     coverage html -d cover
     coverage xml -o cover/coverage.xml
     coverage report --fail-under=46

[testenv:venv]
commands = {posargs}

[doc8]
ignore-path = .venv,.tox,.git,dist,doc,*egg-info,tools,etc,build,*.po,*.pot,integration,releasenotes,*.txt,api-ref/source/samples

[flake8]
show-source = True
ignore = E402,E731,F601,H301,H404,H405,H501,W503,W504,W605
enable-extensions = H203,H106,H213
import-order-style = pep8
builtins = _
# add *.yaml for playbooks/trove-devstack-base.yaml, as it will be matched by
# trove-* in the "filename" configuration.
exclude=.venv,.tox,.git,dist,doc,*egg,tools,etc,build,*.po,*.pot,integration,releasenotes,*.yaml
filename=*.py,trove-*

[hacking]
import_exceptions = trove.common.i18n

[flake8:local-plugins]
extension =
    # T103= checks:check_raised_localized_exceptions
    T105 = checks:no_translate_logs
    T106 = checks:no_log_warn
paths = ./trove/hacking

[testenv:api-ref]
# This environment is called from CI scripts to test and publish
# the API Ref to developer.openstack.org.
deps =
    -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
    -r{toxinidir}/doc/requirements.txt
commands =
  rm -rf api-ref/build
  sphinx-build -W -b html -d api-ref/build/doctrees api-ref/source api-ref/build/html

[testenv:releasenotes]
deps =
    -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
    -r{toxinidir}/doc/requirements.txt
allowlist_externals = rm
commands =
  rm -rf releasenotes/build
  sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html

[testenv:bandit]
commands = bandit -r trove -n5 -x tests

[testenv:bandit-baseline]
commands = bandit-baseline -r trove -n5 -x tests -ii -ll

[testenv:genconfig]
commands = oslo-config-generator --config-file=tools/trove-config-generator.conf

[testenv:genpolicy]
commands = oslopolicy-sample-generator --config-file=tools/trove-policy-generator.conf

[testenv:docs]
deps =
    -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
    -r{toxinidir}/requirements.txt
    -r{toxinidir}/doc/requirements.txt
commands = sphinx-build -W -b html doc/source doc/build/html

[testenv:trovestack]
changedir = {toxinidir}/integration/scripts
passenv = *
commands =
    ./trovestack {posargs}
