[tox]
minversion = 3.18.0
skipsdist = True
envlist = py3,pep8
# Automatic envs (pyXX) will only use the python version appropriate to that
# env and ignore basepython inherited from [testenv] if we set
# ignore_basepython_conflict.
ignore_basepython_conflict = true

[testenv]
basepython = python3
usedevelop = true
setenv =
  VIRTUAL_ENV={envdir}
  PYTHONDONTWRITEBYTECODE=1
deps =
  -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
  -r{toxinidir}/requirements.txt
  -r{toxinidir}/test-requirements.txt
commands =
  stestr run {posargs}
  stestr slowest

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

[testenv:newnote]
deps =
-c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
  -r{toxinidir}/doc/requirements.txt
commands = reno new {posargs}

[testenv:debug]
commands = oslo_debug_helper {posargs}

[testenv:pep8]
# Let's gate pep8 under py3 by default because the py3 checks are stricter.
commands =
  flake8 {posargs}
  # Run bashate during pep8 runs to ensure violations are caught by
  # the check and gate queues.
  bashate -i E006,E042,E043 \
         tools/enable-pre-commit-hook.sh \
         contrib/ci/pre_test_hook.sh \
         contrib/ci/post_test_hook.sh \
         devstack/plugin.sh \
         devstack/upgrade/from-mitaka/upgrade-manila \
         devstack/upgrade/resources.sh \
         devstack/upgrade/shutdown.sh \
         devstack/upgrade/upgrade.sh \
         tools/cover.sh \
         tools/check_logging.sh \
         tools/coding-checks.sh
  {toxinidir}/tools/check_exec.py {toxinidir}/manila
  {toxinidir}/tools/check_logging.sh {toxinidir}/manila

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

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

[testenv:venv]
commands = {posargs}

[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/master}
  -r{toxinidir}/requirements.txt
  -r{toxinidir}/doc/requirements.txt
commands =
  rm -rf doc/build
  sphinx-build -W -b html doc/source doc/build/html
  # Ignore D001 since we allow lines in excess of 79 characters.
  doc8 --ignore D001 --ignore-path .tox --ignore-path doc/build --ignore-path manila.egg-info -e .txt -e .rst -e .inc
allowlist_externals = rm

[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: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, and develop mode disabled
# explicitly to avoid unnecessarily installing the checked-out repo too (this
# further relies on "tox.skipsdist = True" above).
deps = bindep
commands = bindep test
usedevelop = False

[testenv:cover]
setenv =
    {[testenv]setenv}
    PYTHON=coverage run --source manila --parallel-mode
commands =
  {toxinidir}/tools/cover.sh {posargs}

[testenv:fast8]
# Let's run fast8 under py3 by default because the py3 checks are stricter.
commands =
  {toxinidir}/tools/fast8.sh

[testenv:pylint]
deps = -r{toxinidir}/requirements.txt
       -r{toxinidir}/test-requirements.txt
       pylint==2.3.1
allowlist_externals = bash
commands = bash ./tools/coding-checks.sh --pylint {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
  python {toxinidir}/tools/validate-json-files.py {toxinidir}/api-ref/source/samples/
  sphinx-build -W -b html -d api-ref/build/doctrees api-ref/source api-ref/build/html

[testenv:dbrevision]
deps = -r{toxinidir}/requirements.txt
commands = alembic -c manila/db/migrations/alembic.ini revision -m ""{posargs}

[flake8]
# Following checks are ignored on purpose:

# Following checks should be evaluated and fixed:
# E123 closing bracket does not match indentation of opening bracket's line
# E402 module level import not at top of file
# W503 line break before binary operator
# W504 line break after binary operator
ignore = E123,E402,W503,W504
builtins = _
# [H106] Don't put vim configuration in source files.
# [H203] Use assertIs(Not)None to check for None.
# [H904] Use ',' instead of '%', String interpolation should be delayed to be handled by the logging code,
#        rather than being done at the point of the logging call..
enable-extensions = H106,H203,H904
exclude = .git,.tox,.testrepository,.venv,build,cover,dist,doc,*egg,api-ref/build,*/source/conf.py

[hacking]
import_exceptions =
  manila.i18n

[flake8:local-plugins]
extension =
    M310 = checks:CheckLoggingFormatArgs
    M313 = checks:validate_assertTrue
    M323 = checks:check_explicit_underscore_import
    M326 = checks:CheckForTransAdd
    M333 = checks:check_oslo_namespace_imports
    M336 = checks:dict_constructor_with_list_copy
    M337 = checks:no_xrange
    M338 = checks:no_log_warn_check
    M339 = checks:no_third_party_mock
    M354 = checks:check_uuid4
    M359 = checks:no_translate_logs
paths = ./manila/tests/hacking