[tox]
minversion = 3.18.0
envlist = py36,py38,py39,pep8
ignore_basepython_conflict = True


[testenv]
basepython = python3
setenv =
   VIRTUAL_ENV={envdir}
   PYTHONPATH={toxinidir}/StorletSamples/python:{envdir}
   NOSE_WITH_COVERAGE=1
   NOSE_COVER_BRANCHES=1
deps =
  -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/2024.1}
  -r{toxinidir}/requirements.txt
  -r{toxinidir}/test-requirements.txt
  git+https://opendev.org/openstack/swift.git
commands =
    find . -type f -name "*.py[c|o]" -delete
    find . -type d -name "__pycache__" -delete
    stestr run --slowest --concurrency 1 {posargs}

allowlist_externals =
  bash
  find

[testenv:pep8python]
commands =
  flake8
  flake8 --filename=* bin --exclude=bin/*.sh

[testenv:func]
deps =
  -r{toxinidir}/test-requirements.txt
  git+https://opendev.org/openstack/swift.git
setenv =
   VIRTUAL_ENV={envdir}
   STORLET_SAMPLE_PATH={toxinidir}/StorletSamples
   CLUSTER_CONF_DIR={toxinidir}
commands = bash -c "{toxinidir}/.functests jenkins"

[testenv:venv]
commands = {posargs}

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

[testenv:docs]
deps =
  -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/2024.1}
  -r{toxinidir}/requirements.txt
  -r{toxinidir}/doc/requirements.txt
  git+https://opendev.org/openstack/swift.git
commands =
  sphinx-build -a -W -E -b html doc/source doc/build/html

[testenv:debug]
commands = oslo_debug_helper {posargs}

[testenv:bashate]
# Run bashate check for all bash scripts
# Ignores the following rules:
#   E006: Line longer than 79 columns
commands =
  bash -c "grep --recursive --binary-files=without-match \
    --files-with-match '^.!.*\(ba\)\?sh$' \
    --exclude-dir .tox \
    --exclude-dir .git \
    {toxinidir} | xargs bashate --error . --verbose --ignore=E006"

[flake8]
# E123, E125 skipped as they are invalid PEP-8.
# H301: one import per line
# H306: imports not in alphabetical order (time, os)
# H404: multi line docstring should start without a leading new line
# H405: multi line docstring summary not separated with an empty line
# W503 line break before binary operator
# W504 line break after binary operator
ignore = E123,E125,H301,H306,H404,H405,W503,W504
show-source = True
builtins = _
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build

[testenv:pep8]
commands =
  {[testenv:pep8python]commands}
  {[testenv:bashate]commands}
passenv =
  HOME

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

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