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

[testenv]
basepython = python3
usedevelop = True
setenv = VIRTUAL_ENV={envdir}
         LANGUAGE=en_US
         LC_ALL=en_US.utf-8
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}
passenv = HTTP_PROXY, HTTPS_PROXY, NO_PROXY, OS_DEBUG, GENERATE_HASHES

[testenv:functional]
commands =
  stestr --test-path=./masakari/tests/functional run --concurrency=1 --slowest {posargs}

[testenv:genconfig]
commands = oslo-config-generator --config-file=etc/masakari/masakari-config-generator.conf
	   oslo-config-generator --config-file=etc/masakari/masakari-customized-recovery-flow-config-generator.conf

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

[testenv:linters]
skip_install = True
deps =
  -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/zed}
  -r{toxinidir}/test-requirements.txt
  {[testenv:bashate]deps}
commands =
  {[testenv:pep8]commands}
  {[testenv:doc8]commands}
  {[testenv:yamllint]commands}
  {[testenv:bashate]commands}

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

[testenv:doc8]
skip_install = True
deps = {[testenv:linters]deps}
commands =
  doc8 README.rst CONTRIBUTING.rst HACKING.rst doc/source
  doc8 releasenotes/source
  doc8 -e '.yaml' releasenotes/notes
  doc8 -e '.rst' -e '.inc' api-ref/source

[testenv:yamllint]
skip_install = True
deps = {[testenv:linters]deps}
commands = yamllint -s .

[testenv:bashate]
skip_install = True
deps =
  -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/zed}
  bashate
commands =
  bashate devstack/plugin.sh -v --ignore E006 --error E005,E042,E043

[testenv:venv]
commands = {posargs}

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

[testenv:docs]
# NOTE(elod.illes): requirements.txt is needed because otherwise
# dependencies are installed during 'develop-inst' tox phase without
# constraints which could cause failures in stable branches.
deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/zed}
       -r{toxinidir}/requirements.txt
       -r{toxinidir}/doc/requirements.txt
commands =
  sphinx-build -W -b html doc/source doc/build/html

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

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

[testenv:debug]
commands = oslo_debug_helper {posargs}

[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}
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

[flake8]
# E123, E125 skipped as they are invalid PEP-8.

show-source = True

# The below hacking rules by default are disabled should be enabled:
# [H106] Don't put vim configuration in source files.
# [H203] Use assertIs(Not)None to check for None.
# [H904] Delay string interpolations at logging calls.
enable-extensions = H106,H203,H904
# [W504] line break after binary operator (use W503 instead)
ignore = E123,E125,E128,E731,H405,W504
builtins = _
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build

[hacking]
import_exceptions = masakari.i18n

[flake8:local-plugins]
extension =
    M301 = checks:no_db_session_in_public_api
    M302 = checks:use_timeutils_utcnow
    M303 = checks:capital_cfg_help
    M305 = checks:assert_true_instance
    M306 = checks:assert_equal_type
    M308 = checks:no_translate_logs
    M309 = checks:no_import_translation_in_tests
    M310 = checks:no_setting_conf_directly_in_tests
    M315 = checks:no_mutable_default_args
    M316 = checks:check_explicit_underscore_import
    M317 = checks:use_jsonutils
    M318 = checks:assert_true_or_false_with_in
    M319 = checks:assert_raises_regexp
    M320 = checks:dict_constructor_with_list_copy
    M321 = checks:assert_equal_in
    M322 = checks:check_greenthread_spawns
    M323 = checks:check_no_contextlib_nested
    M324 = checks:check_config_option_in_central_place
    M325 = checks:check_doubled_words
    M326 = checks:check_python3_no_iteritems
    M327 = checks:check_python3_no_iterkeys
    M328 = checks:check_python3_no_itervalues
    M329 = checks:no_os_popen
    M331 = checks:no_log_warn
    M332 = checks:yield_followed_by_space
    M333 = checks:check_policy_registration_in_central_place
    M334 = checks:check_policy_enforce
paths = ./masakari/hacking

[testenv:bindep]
skip_install = True
deps = bindep
commands = bindep test

[doc8]
# NOTE(yoctozepto): this is due to multiple violations - it is better to keep
# it limited sanely rather than disable the D001 "Line too long" rule altogether
max-line-length = 105
