[tox]
envlist = py38,pep8,genpolicy
minversion = 3.14.4
skipsdist = True
# this allows tox to infer the base python from the environment name
# and override any basepython configured in this file
ignore_basepython_conflict = true

[testenv]
basepython = python3
usedevelop = True
install_command = pip install {opts} {packages}
setenv =
    VIRTUAL_ENV={envdir}
    DISCOVER_DIRECTORY=sahara/tests/unit
deps =
    -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/wallaby}
    -r{toxinidir}/requirements.txt
    -r{toxinidir}/test-requirements.txt
commands = stestr run {posargs}
passenv = http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY

[testenv:cover]
setenv =
    PACKAGE_NAME=sahara
commands = {toxinidir}/tools/cover.sh {posargs}

[testenv:debug-py36]
basepython = python3.6
commands = oslo_debug_helper -t sahara/tests/unit {posargs}

[testenv:debug-py37]
basepython = python3.7
commands = oslo_debug_helper -t sahara/tests/unit {posargs}

[testenv:pep8]
deps =
  -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/wallaby}
  -r{toxinidir}/requirements.txt
  -r{toxinidir}/test-requirements.txt
  -r{toxinidir}/doc/requirements.txt
commands =
    flake8 {posargs}
    doc8 doc/source
    # Run bashate checks
    bash -c "find devstack -not -name \*.template -and -not -name README.rst -and -not -name \*.json -type f -print0 | xargs -0 bashate -v"
    # Run security linter
    bandit -c bandit.yaml -r sahara -n5 -p sahara_default -x tests

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

[testenv:venv]
commands = {posargs}

[testenv:images]
sitepackages = True
commands = {posargs}

[testenv:docs]
deps =
  -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/wallaby}
  -r{toxinidir}/requirements.txt
  -r{toxinidir}/doc/requirements.txt
commands =
    rm -rf doc/html doc/build
    rm -rf api-ref/build api-ref/html
    rm -rf doc/source/apidoc doc/source/api
    sphinx-build -W -b html doc/source doc/build/html
    sphinx-build -W -b html -d api-ref/build/doctrees api-ref/source api-ref/build/html
    whereto doc/source/_extra/.htaccess doc/test/redirect-tests.txt
whitelist_externals = rm

[testenv:api-ref]
deps =
  -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/wallaby}
  -r{toxinidir}/doc/requirements.txt
install_command = pip install -U --force-reinstall {opts} {packages}
commands =
  rm -rf api-ref/build api-ref/html
  sphinx-build -W -b html -d api-ref/build/doctrees api-ref/source api-ref/build/html
whitelist_externals = rm


[testenv:pylint]
setenv = VIRTUAL_ENV={envdir}
commands = bash tools/lintstack.sh

[testenv:genconfig]
commands =
    oslo-config-generator --config-file tools/config/config-generator.sahara.conf \
    --output-file etc/sahara/sahara.conf.sample

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

[testenv:debug]
# It runs tests from the specified dir (default is sahara/tests)
# in interactive mode, so, you could use pbr for tests debug.
# Example usage: tox -e debug -- -t sahara/tests/unit some.test.path
# https://docs.openstack.org/oslotest/latest/features.html#debugging-with-oslo-debug-helper
commands = oslo_debug_helper -t sahara/tests/unit {posargs}

[testenv:bandit]
deps = -r{toxinidir}/test-requirements.txt
commands = bandit -c bandit.yaml -r sahara -n5 -p sahara_default -x tests

[flake8]
show-source = true
builtins = _
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,tools
# [H904] Delay string interpolations at logging calls
# [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
enable-extensions=H904,H106,H203,H204,H205
# [E123] Closing bracket does not match indentation of opening bracket's line
# [E226] Missing whitespace around arithmetic operator
# [E402] Module level import not at top of file
# [E731] Do not assign a lambda expression, use a def
# [W503] Line break occurred before a binary operator
# [W504] Line break occurred after a binary operator
# [W605] Invalid escape sequence 'x'
ignore=E123,E226,E402,E731,W503,W504,W605

[hacking]
import_exceptions = sahara.i18n

[flake8:local-plugins]
extension =
    S361 = checks:import_db_only_in_conductor
    S362 = checks:hacking_no_author_attr
    S363 = checks:check_oslo_namespace_imports
    S364 = commit_message:OnceGitCheckCommitTitleBug
    S365 = commit_message:OnceGitCheckCommitTitleLength
    S368 = checks:dict_constructor_with_list_copy
    S373 = logging_checks:no_translate_logs
    S374 = logging_checks:accepted_log_levels
    S375 = checks:use_jsonutils
    S360 = checks:no_mutable_default_args
paths =
  ./sahara/utils/hacking

[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

[testenv:lower-constraints]
deps =
  -c{toxinidir}/lower-constraints.txt
  -r{toxinidir}/test-requirements.txt
  -r{toxinidir}/requirements.txt
