[tox]
minversion = 3.18.0
envlist = py3,pep8
ignore_basepython_conflict = True

[testenv]
basepython = python3
allowlist_externals =
    find
    rm
setenv = VIRTUAL_ENV={envdir}
         PYTHONWARNINGS=default::DeprecationWarning
usedevelop = True

deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
       -r{toxinidir}/requirements.txt
       -r{toxinidir}/test-requirements.txt

commands_pre =
  # We need the patch https://review.opendev.org/c/openstack/cloudkitty/+/861786;
  # therefore, until it is released a new version of WSME, we will need to manually
  # install WSME with `tox`.
  pip install git+https://opendev.org/x/wsme@a45e0af97e2e8362277f160d0f2b737590e367d1

commands =
  find . -type f -name "*.py[co]" -delete
  rm -f .testrepository/times.dbm
  stestr run {posargs}

[testenv:debug]
commands = oslo_debug_helper {posargs}

[testenv:pep8]
commands =
    flake8 {posargs} cloudkitty
    doc8 {posargs}

[testenv:bandit]
deps = -r{toxinidir}/test-requirements.txt
commands = bandit -r cloudkitty -n5 -x cloudkitty/tests/* -ll

[testenv:cover]
setenv =
    VIRTUAL_ENV={envdir}
    PYTHON=coverage run --source cloudkitty --parallel-mode
commands =
    stestr run {posargs}
    coverage combine
    coverage html -d cover
    coverage xml -o cover/coverage.xml
    coverage report

[testenv:genconfig]
commands =
  oslo-config-generator --config-file etc/oslo-config-generator/cloudkitty.conf

[testenv:genpolicy]
commands = oslopolicy-sample-generator --config-file=etc/oslo-policy-generator/cloudkitty.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 --keep-going -b html doc/source doc/build/html

# TODO(smcginnis) Temporarily disabling this as it fails. Error is that
# something is too large, likely from pulling in one of the conf sample files
# [testenv:pdf-docs]
# envdir = {toxworkdir}/docs
# allowlist_externals =
#   make
# commands =
#   sphinx-build -W --keep-going -b latex doc/source doc/build/pdf
#   make -C doc/build/pdf

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

[testenv:venv]
commands = {posargs}

[flake8]
filename = *.py,app.wsgi
exclude = .git,.venv,.tox,dist,doc,*egg,build,.ropeproject,releasenotes

[doc8]
ignore-path = .venv,.git,.tox,.tmp,*cloudkitty/locale*,*lib/python*,cloudkitty.egg*,doc/build,releasenotes/*

[hacking]
import_exceptions = cloudkitty.i18n

[flake8:local-plugins]
extension =
    C310 = checks:CheckLoggingFormatArgs
    C311 = checks:validate_assertIsNone
    C312 = checks:validate_assertTrue
    C313 = checks:no_translate_logs
    C314 = checks:CheckForStrUnicodeExc
    C315 = checks:CheckForTransAdd
    C317 = checks:check_oslo_namespace_imports
    C318 = checks:dict_constructor_with_list_copy
    C319 = checks:no_xrange
    C320 = checks:no_log_warn_check
    C321 = checks:check_explicit_underscore_import
    C322 = checks:assert_raises_regexp
paths = ./cloudkitty/hacking

[testenv:releasenotes]
deps = {[testenv:docs]deps}
commands = sphinx-build -a -E -W -d releasenotes/build/doctrees --keep-going -b html releasenotes/source releasenotes/build/html