[tox]
minversion = 3.18.0
requires = virtualenv>=20.4.2
skipsdist = True
envlist = pep8,py3,functional
# this allows tox to infer the base python from the environment name
# and override any basepython configured in this file
ignore_basepython_conflict=true

[testenv]
usedevelop = true
setenv =
  VIRTUAL_ENV={envdir}
  OS_STDOUT_CAPTURE=1
  OS_STDERR_CAPTURE=1

deps = 
  -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/2024.1}
  -r{toxinidir}/requirements.txt
  -r{toxinidir}/test-requirements.txt

allowlist_externals =
  find
  bash
  isort
  echo
passenv =
  *_proxy
  *_PROXY

[testenv:venv]
deps =
  {[testenv]deps}
extras =
commands =
  {posargs}

[testenv:policyenv]
deps =
  {[testenv]deps}
description =
  Policy Env.
extras =
commands =
  bash tools/post_install.sh
  {posargs}

[testenv:mypy]
description =
  Run type checks.
envdir = {toxworkdir}/shared
extras =
commands =
  mypy skyline_apiserver

[testenv:pep8]
description =
  Run style checks.
envdir = {toxworkdir}/shared
deps =
  {[testenv]deps}
extras =
commands =
  {[testenv:mypy]commands}
  isort --check-only --diff skyline_apiserver
  black --check --diff --color skyline_apiserver --line-length 98
  flake8 {posargs} .

[testenv:py{3,38,39,310,311}]
description =
  Run pytest.
deps =
  {[testenv]deps}
extras =
commands =
  pytest

[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
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 .venv --ignore-path doc/build --ignore-path skyline_apiserver.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:releasenotes]
description =
  Generate release notes.
envdir = {toxworkdir}/shared
commands =
  sphinx-build -W --keep-going -b html -j auto releasenotes/source releasenotes/build/html

[testenv:genswagger]
description =
  Generate swagger files.
envdir = {toxworkdir}/shared
commands =
  skyline-swagger-generator -o swagger.json

[testenv:genconfig]
description =
  Generate config files.
envdir = {toxworkdir}/shared
commands =
  skyline-sample-config-generator -o etc/skyline.yaml.sample

[testenv:gennginx]
description =
  Generate nginx config files.
deps =
  {[testenv]deps}
  skyline-console
commands =
  skyline-nginx-generator -o etc/nginx.conf

[testenv:functional]
commands =
  echo "TODO: Add functional test for skyline-apiserver"

[testenv:pep8-format]
description =
  Run code format.
envdir = {toxworkdir}/shared
deps =
  {[testenv]deps}
extras =
commands =
  isort skyline_apiserver
  black skyline_apiserver --line-length 98

[flake8]
# E203 whitespace before ':'
extend-ignore = E203
max-line-length = 99
max-doc-length = 99
show-source = True
exclude =  .venv,.git,.tox,dist,*lib/python*,*egg,build,releasenotes
