[tox]
envlist =
    {pypy3.9,3.8,3.9,3.10,3.11,3.12}-unit
    {pypy3.9,3.8,3.9,3.10,3.11,3.12}-linux-integration-py-amqp
    {pypy3.9,3.8,3.9,3.10,3.11}-linux-integration-redis
    {pypy3.9,3.8,3.9,3.10,3.11}-linux-integration-mongodb
    {3.8,3.9,3.10,3.11,3.12}-linux-integration-kafka
    flake8
    apicheck
    pydocstyle

requires =
    tox-docker<=4.1
    requests<2.32.0

[gh-actions]
python =
    3.8: py38
    3.9: py39
    3.10: py310, mypy
    3.11: py311
    3.12: py312

[testenv]
sitepackages = False
setenv = C_DEBUG_TEST = 1
passenv =
  DISTUTILS_USE_SDK
deps=
    -r{toxinidir}/requirements/dev.txt
    apicheck,pypy3.9,3.8,3.9,3.10,3.11,3.12: -r{toxinidir}/requirements/default.txt
    apicheck,pypy3.9,3.8,3.9,3.10,3.11,3.12: -r{toxinidir}/requirements/test.txt
    apicheck,pypy3.9,3.8,3.9,3.10,3.11,3.12: -r{toxinidir}/requirements/test-ci.txt
    apicheck,3.8-linux,3.9-linux,3.10-linux,3.11-linux,3.12-linux: -r{toxinidir}/requirements/extras/confluentkafka.txt
    apicheck,linkcheck: -r{toxinidir}/requirements/docs.txt
    flake8,pydocstyle,mypy: -r{toxinidir}/requirements/pkgutils.txt

commands =
    unit: python -bb -m pytest -rxs -xv --cov=kombu --cov-report=xml --no-cov-on-fail {posargs}
    integration-py-amqp: pytest -xv -E py-amqp t/integration {posargs:-n2}
    integration-redis: pytest -xv -E redis t/integration {posargs:-n2}
    integration-mongodb: pytest -xv -E mongodb t/integration {posargs:-n2}
    integration-kafka: pytest -xv -E kafka t/integration {posargs:-n2}

basepython =
    pypy3.9: pypy3.9
    pypy3.8: pypy3.8
    3.8: python3.8
    3.9: python3.9
    3.10,apicheck,pydocstyle,flake8,linkcheck,cov,mypy: python3.10
    3.11: python3.11
    3.12: python3.12

install_command = python -m pip --disable-pip-version-check install {opts} {packages}

docker =
    integration-py-amqp: rabbitmq
    integration-redis: redis
    integration-mongodb: mongodb
    integration-kafka: zookeeper
    integration-kafka: kafka

dockerenv =
    PYAMQP_INTEGRATION_INSTANCE=1
    RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS=-rabbit tcp_listeners [5672]

[docker:rabbitmq]
image = rabbitmq
ports = 5672:5672/tcp
healthcheck_cmd = /bin/bash -c 'rabbitmq-diagnostics ping -q'
healthcheck_interval = 10
healthcheck_timeout = 10
healthcheck_retries = 30
healthcheck_start_period = 5

[docker:redis]
image = redis
ports = 6379:6379/tcp
healthcheck_cmd = /bin/sh -c 'redis-cli ping'
healthcheck_interval = 10
healthcheck_timeout = 10
healthcheck_retries = 30
healthcheck_start_period = 5

[docker:mongodb]
image = mongo
ports = 27017:27017/tcp
healthcheck_cmd = /usr/bin/mongosh --eval 'db.runCommand("ping")'
healthcheck_interval = 10
healthcheck_timeout = 10
healthcheck_retries = 30
healthcheck_start_period = 5

[docker:zookeeper]
image = bitnami/zookeeper:latest
ports = 2181:2181/tcp
healthcheck_interval = 10
healthcheck_timeout = 10
healthcheck_retries = 30
healthcheck_start_period = 5
environment = ALLOW_ANONYMOUS_LOGIN=yes

[docker:kafka]
image = bitnami/kafka:latest
ports =
    9092:9092/tcp
healthcheck_cmd = /bin/bash -c 'kafka-topics.sh --list --bootstrap-server 127.0.0.1:9092'
healthcheck_interval = 10
healthcheck_timeout = 10
healthcheck_retries = 30
healthcheck_start_period = 5
links =
    zookeeper:zookeeper
environment =
    KAFKA_BROKER_ID=1
    KAFKA_CFG_LISTENERS=PLAINTEXT://:9092
    KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9092
    KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
    ALLOW_PLAINTEXT_LISTENER=yes

[testenv:apicheck]
commands = pip install -U -r{toxinidir}/requirements/dev.txt
    sphinx-build -j2 -b apicheck -d {envtmpdir}/doctrees docs docs/_build/apicheck

[testenv:linkcheck]
commands = pip install -U -r{toxinidir}/requirements/dev.txt
    sphinx-build -j2 -W -b linkcheck -d {envtmpdir}/doctrees docs docs/_build/linkcheck

[testenv:flake8]
commands =
    flake8 -j2 {toxinidir}/kombu {toxinidir}/t

[testenv:pydocstyle]
commands =
    pydocstyle {toxinidir}/kombu

[testenv:mypy]
commands = python -m mypy --config-file setup.cfg