[tox]
minversion = 4.4.0
envlist = py3,pep8
ignore_basepython_conflict=true

[testenv]
constrain_package_deps = true
usedevelop = True
setenv =
   PYTHONWARNINGS=default::DeprecationWarning
deps =
   -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/2024.2}
   -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:pep8]
deps =
    bashate~=2.1.0 # Apache-2.0
    flake8-import-order~=0.18.0 # LGPLv3
    hacking~=6.1.0 # Apache-2.0
    pycodestyle>=2.0.0,<3.0.0 # MIT
allowlist_externals = bash
                      {toxinidir}/tools/run_bashate.sh
commands =
  bash tools/flake8wrap.sh {posargs}
  # Run bashate during pep8 runs to ensure violations are caught by
  # the check and gate queues.
  {toxinidir}/tools/run_bashate.sh {toxinidir}/devstack

[testenv:venv]
commands = {posargs}

[testenv:cover]
setenv = VIRTUAL_ENV={envdir}
         LANGUAGE=en_US
         PYTHON=coverage run --source networking_baremetal --parallel-mode
commands =
    coverage erase
    stestr run {posargs}
    coverage combine
    coverage html -d cover
    coverage xml -o cover/coverage.xml
    coverage report --omit='*test*'

[testenv:docs]
setenv = PYTHONHASHSEED=0
sitepackages = False
deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/2024.2}
       -r{toxinidir}/requirements.txt
       -r{toxinidir}/doc/requirements.txt
commands =
  sphinx-build -W -b html doc/source doc/build/html

[testenv:pdf-docs]
allowlist_externals = make
setenv = PYTHONHASHSEED=0
sitepackages = False
deps = {[testenv:docs]deps}
commands =
  sphinx-build -b latex doc/source doc/build/pdf
  make -C doc/build/pdf

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

[testenv:genconfig]
deps =
   -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/2024.2}
   -r{toxinidir}/test-requirements.txt
commands =
  oslo-config-generator --config-file=tools/config/networking-baremetal-ironic-neutron-agent.conf
  oslo-config-generator --config-file=tools/config/networking-baremetal-common-device-driver-opts.conf
  oslo-config-generator --config-file=tools/config/networking-baremetal-netconf-openconfig-driver-opts.conf

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

[flake8]
show-source = True
# E123, E125 skipped as they are invalid PEP-8.
# [W503] Line break occurred before a binary operator. Conflicts with W504.
ignore = E123,E125,W503
# [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.
# [H210] Require 'autospec', 'spec', or 'spec_set' in mock.patch/mock.patch.object calls
# [H904] Delay string interpolations at logging calls.
enable-extensions=H106,H203,H204,H205,H210,H904
builtins = _
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build
import-order-style = pep8
application-import-names = networking_baremetal
filename = *.py
per-file-ignores =
    networking_baremetal/agent/ironic_neutron_agent.py:E402

[testenv:codespell]
description =
  Run codespell to check spelling
deps = codespell
# note(JayF): {posargs} lets us run `tox -ecodespell -- -w` to get codespell
#             to correct spelling issues in our code it's aware of.
commands =
  codespell {posargs}