[tox]
minversion = 3.18.0
envlist = docs,py38,pep8
skipsdist = True
ignore_basepython_conflict = True

[testenv]
basepython = python3
usedevelop = True
setenv =
   VIRTUAL_ENV={envdir}
   PYTHONWARNINGS=default::DeprecationWarning
   OS_LOG_CAPTURE={env:OS_LOG_CAPTURE:true}
   OS_STDOUT_CAPTURE={env:OS_STDOUT_CAPTURE:true}
   OS_STDERR_CAPTURE={env:OS_STDERR_CAPTURE:true}
   OS_TEST_TIMEOUT=60
deps =
  -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/zed}
  -r{toxinidir}/requirements.txt
  -r{toxinidir}/test-requirements.txt
commands = stestr run {posargs}

[testenv:pep8]
commands = flake8
           doc8 --ignore-path doc/source/contributor/modules \
           doc/source octavia_lib HACKING.rst README.rst
           # Run security linter
           bandit -r octavia_lib -ll -ii -x octavia_lib/tests
           {toxinidir}/tools/coding-checks.sh --pylint '{posargs}'

[testenv:venv]
commands = {posargs}

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

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

[testenv:pdf-docs]
deps = {[testenv:docs]deps}
allowlist_externals =
  make
  rm
commands =
  rm -rf doc/build/pdf
  sphinx-build -W -b latex doc/source doc/build/pdf
  make -C doc/build/pdf

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

[testenv:debug]
commands = oslo_debug_helper {posargs}

[flake8]
# W504 line break after binary operator
ignore = W504
show-source = True
builtins = _
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build
# [H106]: Don't put vim configuration in source files
# [H203]: Use assertIs(Not)None to check for None
# [H204]: Use assert(Not)Equal to check for equality
# [H205]: Use assert(Greater|Less)(Equal) for comparison
# [H904]: Delay string interpolations at logging calls
enable-extensions=H106,H203,H204,H205,H904

[hacking]
import_exceptions = octavia_lib.i18n

[flake8:local-plugins]
extension =
  O316 = checks:assert_true_instance
  O318 = checks:assert_equal_or_not_none
  O323 = checks:assert_equal_true_or_false
  O324 = checks:no_mutable_default_args
  O338 = checks:assert_equal_in
  O339 = checks:no_log_warn
  O341 = checks:no_translate_logs
  O342 = checks:check_raised_localized_exceptions
  O343 = checks:check_no_basestring
  O345 = checks:check_no_eventlet_imports
  O346 = checks:check_line_continuation_no_backslash
  O348 = checks:check_no_logging_imports
  O501 = checks:check_no_octavia_namespace_imports
paths =
  ./octavia_lib/hacking

[doc8]
max-line-length = 79

[testenv:requirements]
deps =
  -egit+https://opendev.org/openstack/requirements#egg=openstack-requirements
allowlist_externals = sh
commands =
    sh -c '{envdir}/src/openstack-requirements/playbooks/files/project-requirements-change.py --req {envdir}/src/openstack-requirements --local {toxinidir} master'
