[tox]
envlist =
    py37-lint,
    py38-lint,
    py39-lint,
    py310-lint,
    black-check,
    py{38,37}-Plone{52},
    py{39,310}-Plone{60},
#    docs,
#    coverage-report,

skip_missing_interpreters = True


[gh-actions]
python =
    3.6: py36
    3.7: py37
    3.8: py38
    3.9: py39
    3.10: py310


[gh-actions:env]
PLONE-VERSION =
    Plone52: Plone52
    Plone60: Plone60


[testenv]
skip_install = true

extras =
    develop
    test

commands =
    {envbindir}/buildout -q -c {toxinidir}/{env:version_file} buildout:directory={envdir} buildout:develop={toxinidir} bootstrap
#    {envbindir}/buildout -c {toxinidir}/{env:version_file} buildout:directory={envdir} buildout:develop={toxinidir} annotate
    {envbindir}/buildout -n -qq -c {toxinidir}/{env:version_file} buildout:directory={envdir} buildout:develop={toxinidir} install test robot
    coverage run {envbindir}/test -v1 --auto-color {posargs}
    # coverage run {envbindir}/test -v --all -t robot {posargs}

setenv =
    COVERAGE_FILE=.coverage.{envname}
    # version_file=test_plone60.cfg
    Plone52: version_file=test_plone52.cfg
    Plone60: version_file=test_plone60.cfg

deps =
    Plone52: -rrequirements_plone52.txt
#    Plone52: -cconstraints_plone52.txt
    Plone60: -rrequirements_plone60.txt
#    Plone60: -cconstraints_plone60.txt
    coverage


[testenv:coverage-report]
skip_install = true
usedevelop = True
basepython = python3.9

deps =
    coverage
    -cconstraints_plone60.txt

setenv =
    COVERAGE_FILE=.coverage

commands =
    coverage erase
    coverage combine
    coverage html
    coverage xml
    coverage report


[lint]
skip_install = true

deps =
    -cconstraints.txt
    isort
    flake8
    # helper to generate HTML reports:
    # flake8-html>=0.4.3
    # Useful flake8 plugins that are Python and Plone specific:
    ; flake8-coding
    flake8-debugger
    flake8-deprecated
    flake8-print
    #flake8-pytest
    flake8-todo
    mccabe
    # Potential flake8 plugins that should be used:  # TBD
    #flake8-blind-except
    #flake8-commas
    #flake8-docstrings
    #flake8-mypy
    #flake8-pep3101
    #flake8-plone-hasattr
    #flake8-string-format
    #flake8_strict
    #flake8-quotes
    #flake8-polyfill

commands =
    mkdir -p {toxinidir}/reports/flake8
    flake8 --doctests {toxinidir}/src {toxinidir}/setup.py
    isort --check-only {toxinidir}/src {toxinidir}/setup.py
    # black --check --diff -v {toxinidir}/src {toxinidir}/setup.py

allowlist_externals =
    mkdir


[testenv:isort-apply]
skip_install = true

deps =
    -cconstraints.txt
    isort

commands =
    isort {toxinidir}/src {toxinidir}/setup.py


[testenv:black-check]
basepython = python3.9
skip_install = True
deps =
    -cconstraints.txt
    black

commands =
    black --check --diff -v src setup.py


[testenv:black-enforce]
basepython = python3.9
skip_install = True
deps =
    -cconstraints.txt
    black

commands =
    black -v src setup.py


[testenv:py37-lint]
basepython = python3.7
skip_install = true
deps = {[lint]deps}
commands = {[lint]commands}
allowlist_externals = {[lint]allowlist_externals}

[testenv:py38-lint]
basepython = python3.8
skip_install = true
deps = {[lint]deps}
commands = {[lint]commands}
allowlist_externals = {[lint]allowlist_externals}

[testenv:py39-lint]
basepython = python3.9
skip_install = true
deps = {[lint]deps}
commands = {[lint]commands}
allowlist_externals = {[lint]allowlist_externals}

[testenv:py310-lint]
basepython = python3.10
skip_install = true
deps = {[lint]deps}
commands = {[lint]commands}
allowlist_externals = {[lint]allowlist_externals}

[testenv:docs]
skip_install = true

deps =
    Sphinx

commands =
    sphinx-build -b html -d _build/docs/doctrees docs _build/docs/html
