[tox]
envlist = py3,pep8
minversion = 3.18.0
skipsdist = False
ignore_basepython_conflict = True

[testenv]
basepython = {env:TOX_PYTHON:python3}
setenv = VIRTUAL_ENV={envdir}
         OS_LOG_CAPTURE={env:OS_LOG_CAPTURE:true}
         OS_STDOUT_CAPTURE={env:OS_STDOUT_CAPTURE:true}
         OS_STDERR_CAPTURE={env:OS_STDERR_CAPTURE:true}
         PYTHONWARNINGS=default::DeprecationWarning
passenv = TRACE_FAILONLY
usedevelop = True
deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/2025.2}
       -r{toxinidir}/requirements.txt
       -r{toxinidir}/test-requirements.txt
allowlist_externals =
    bash
    find
commands =
  find . -type f -name "*.py[c|o]" -delete
  find -path "*/__pycache__*" -delete
  stestr run {posargs}
# there is also secret magic in ostestr which lets you run in a fail only
# mode. To do this define the TRACE_FAILONLY environmental variable.

[testenv:functional]
setenv =
  {[testenv]setenv}
  OS_TEST_PATH=./networking_sfc/tests/functional

[testenv:dsvm-functional-gate]
setenv =
    {[testenv]setenv}
    OS_TEST_PATH=./networking_sfc/tests/functional
    OS_SUDO_TESTING=1
    OS_FAIL_ON_MISSING_DEPS=1
    OS_TEST_TIMEOUT=180
    OS_TESTR_CONCURRENCY=1
    OS_LOG_PATH={env:OS_LOG_PATH:/opt/stack/logs}
allowlist_externals =
  bash
  cp
  sudo
commands = stestr run {posargs}

[testenv:pep8]
deps =
  {[testenv]deps}
  pylint==3.2.0 # GPLv2
commands =
  flake8
  pylint --rcfile=.pylintrc --output-format=colorized {posargs:networking_sfc}
  bash {toxinidir}/tools/check_unit_test_structure.sh
  neutron-db-manage --subproject networking-sfc --database-connection sqlite:// check_migration
  {[testenv:genconfig]commands}
  {[testenv:genpolicy]commands}
allowlist_externals = bash

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

[testenv:venv]
commands = {posargs}

[testenv:docs]
deps =
  -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/2025.2}
  -r{toxinidir}/doc/requirements.txt
commands = sphinx-build -W -b html -d doc/build/doctrees 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

[flake8]
# N530 direct neutron imports not allowed
# W504 Line break occurred after a binary operator
# E126 continuation line over-indented for hanging indent
# E128 continuation line under-indented for visual indent
# H405 multi line docstring summary not separated with an empty line
# I202 Additional newline in a group of imports
# E731 do not assign a lambda expression, use a def
# W504 line break after binary operator
ignore = E126,E128,E731,I202,H405,N530,W504
# 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
show-source = true
builtins = _
exclude = ./.*,build,dist
import-order-style = pep8

[flake8:local-plugins]
extension =
  H999 = checks:check_no_eventlet_import
paths = ./networking_sfc/hacking

[hacking]
import_exceptions = networking_sfc._i18n

[testenv:api-ref]
allowlist_externals = rm
deps = {[testenv:docs]deps}
commands =
  rm -rf api-ref/build
  sphinx-build -W -b html -d api-ref/build/doctrees api-ref/source api-ref/build/html

[testenv:debug]
commands = oslo_debug_helper -t networking_sfc/tests {posargs}

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

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

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

[testenv:dev]
# run locally (not in the gate) using editable mode
# https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs
commands =
    pip install -q -e "git+https://opendev.org/openstack/neutron#egg=neutron"

[testenv:py-dev]
commands =
    {[testenv:dev]commands}
    {[testenv]commands}

[testenv:pep8-dev]
deps =
    {[testenv]deps}
commands =
    {[testenv:dev]commands}
    {[testenv:pep8]commands}

# 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
