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

[testenv]
basepython = python3
usedevelop = True
allowlist_externals = rm
deps =
       -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
       -r{toxinidir}/requirements.txt
       -r{toxinidir}/test-requirements.txt
setenv = VIRTUAL_ENV={envdir}
         DISCOVER_DIRECTORY=blazar/tests
         PYTHONHASHSEED=0
commands =
    stestr run --slowest {posargs}

sitepackages = False

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

[testenv:pep8]
skip_install = True
commands = flake8 {posargs}

[testenv:venv]
commands = {posargs}

[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 =
    rm -rf doc/html doc/build
    rm -rf doc/source/apidoc doc/source/api
    sphinx-build -W -b html doc/source doc/build/html

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

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

[flake8]
show-source = true
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,tools,api-ref
# NOTE(tonyb): Ignore a few errors/warnings that are now "on by default".
# W503 line break before binary operator
# W504 line break after binary operator
# E402 module level import not at top of file
ignore=H105,H238,E123,E402,W503,W504
# [H904] Delay string interpolations at logging calls.
enable-extensions=H904
# To get a list of functions that have a complexity of 17 or more, set
# max-complexity to 17 and run 'tox -epep8'.
# 23 is currently the most complex thing we have:
# 'ManagerService.update_lease' - blazar/manager/service.py
max-complexity=23

[flake8:local-plugins]
extension =
  Bl301 = checks:no_translate_logs
  Bl302 = checks:no_log_warn
paths = ./blazar/hacking

[testenv:pylint]
deps = -r{toxinidir}/requirements.txt
       pylint==1.9.1
commands = pylint blazar

[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

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

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

# This environment can be used to quickly validate that all needed system
# packages required to successfully execute test targets are installed
[testenv:bindep]
# Do not install any requirements. We want this to be fast and work even if
# system dependencies are missing, since it's used to tell you what system
# dependencies are missing! This also means that bindep must be installed
# separately, outside of the requirements files.
deps = bindep
commands = bindep test
