[tox]
minversion = 3.0.0
envlist = py{39,311,312,313}-{flake8,mypy,unit,unitbase,bandit,prospector,sphinx,man},py39-{unit-min,man-min}
skip_missing_interpreters = True

[testenv]
usedevelop = True
allowlist_externals =
    rm
    sed
    {toxinidir}/cumin/tests/integration/docker.sh
description =
    flake8: Style consistency checker
    mypy: Static analyzer for type annotations
    unit: Run unit tests
    unitbase: Run unit tests with base dependencies only
    bandit: Security-oriented static analyzer
    prospector: Static analysis multi-tool
    sphinx: Build html documentation
    integration: Run integration tests
    man: Build the man page
    min: [minimum supported version of dependencies]
    py39: (Python 3.9)
    py311: (Python 3.11)
    py312: (Python 3.12)
    py313: (Python 3.13)
commands =
    flake8: flake8 setup.py cumin doc
    mypy: mypy cumin/
    unit: py.test -p no:logging --strict-markers --cov-report=term-missing --cov=cumin cumin/tests/unit {posargs}
    unitbase: py.test -p no:logging --strict-markers --cov-report=term-missing --cov=cumin --ignore=cumin/tests/unit/backends/test_openstack.py cumin/tests/unit {posargs}
    # Avoid bandit import_subprocess (B404) overall, the import itself it not unsafe
    bandit: bandit -l -i -r --skip B404 --exclude './cumin/tests' ./cumin/
    # Avoid bandit assert_used (B101) in tests
    bandit: bandit -l -i -r --skip B101,B404 cumin/tests
    prospector: prospector --profile "{toxinidir}/prospector.yaml" cumin/
    sphinx: sphinx-build -b html doc/source/ doc/build/html
    man: sphinx-build -b man doc/source/ doc/build/man
    # Fix missing space after bold blocks in man page: https://github.com/ribozz/sphinx-argparse/issues/80
    # Use a syntax that works both on BSD/MacOS and Linux
    man: sed -i.orig -e 's/^\.B/.B /' '{toxinidir}/doc/build/man/cumin.1'
    man: rm -fv '{toxinidir}/doc/build/man/cumin.1.orig'
    integration: "{toxinidir}/cumin/tests/integration/docker.sh" "transports/clustershell" {posargs}
deps =
    # Use install_requires and the additional extras_require[NAME] from setup.py
    unitbase: .[tests-base]
    min: .[tests-min]
    prospector: .[prospector]
    !min-!unitbase-!prospector: .[tests]
setenv =
    min: CUMIN_MIN_DEPS=1

# Needed as long as tox 3 is supported
[testenv:py39-integration]
[testenv:py39-integration-min]
[testenv:py311-integration]
[testenv:py312-integration]
[testenv:py313-integration]

[flake8]
max-line-length = 120
statistics = True
ignore = W503
import-order-style = edited
# Do not specify application-package-names to avoid to manually keep the list of Org-wide packages
# application-package-names =
# Mark cumin as local to separate its imports
application-import-names = cumin
