[tox]
envlist =
    py38-lint
    py39-lint
    py310-lint
    black-check
    docs
    py{310,39,38}-packagetests
    py{38}-skeletontests-Plone{52}-template-addon
    py{310,39}-skeletontests-Plone{60}-template-addon
    py{38}-skeletontests-Plone{52}-template-addon_all
    py{310,39}-skeletontests-Plone{60}-template-addon_all
    py{310,39}-skeletontests-Plone{60}-template-addon_theme_barceoneta
    py{38,39,310}-skeletontests-Plone{60}-template-addon_mockup_pattern
    coverage-report

skip_missing_interpreters = True

[gh-actions]
python =
    3.8: py38
    3.9: py39
    3.10: py310

[testenv]
usedevelop = True
extras =
    test

basepython:
    py38: python3.8
    py39: python3.9
    py310: python3.10

commands =
    mkdir -p {toxinidir}/_build/reports/coverage {toxinidir}/_build/reports/pytest
    packagetests: pytest --cov=bobtemplates.plone --cov-config=setup.cfg --cov-report=xml --html={toxinidir}/_build/reports/pytest/report-{envname}.html --self-contained-html package_tests {posargs}
    template-addon: pytest skeleton-tests/test_addon.py {posargs}
    template-addon_all: pytest skeleton-tests/test_addon_all.py {posargs}
    template-addon_theme_barceoneta: pytest skeleton-tests/test_addon_theme_barceloneta.py {posargs}
    template-addon_mockup_pattern: pytest skeleton-tests/test_addon_mockup_pattern.py {posargs}

setenv =
    COVERAGE_FILE=.coverage.{envname}
    Plone52: VERSION=5.2-latest
    Plone60: VERSION=6.0-latest
    ENVNAME={envname}

passenv =
    VERBOSE
    PACKAGENAME

deps =
    -cconstraints.txt
    pdbpp
    pytest
    pytest-cov
#    pytest-remove-stale-bytecode
    pytest-mock
    pytest-html

allowlist_externals =
    mkdir

depends =
    {py310}: coverage-clean
    coverage-report: py310


[testenv:coverage-report]
#usedevelop = True
basepython = python3.9
deps =
    -cconstraints.txt
    coverage
depends =
    py{39}-packagetests,

#setenv =
#    COVERAGE_FILE=.coverage

skip_install = true

commands =
    coverage combine
    coverage report
    coverage html
    coverage xml

[testenv:coverage-clean]
deps = coverage
skip_install = true
commands = coverage erase

[testenv:isort-apply]
basepython = python3.10
deps =
    -cconstraints.txt
    isort

commands =
    isort {toxinidir}/bobtemplates setup.py skeleton-tests package_tests

[testenv:autopep8]
basepython = python3.9
skip_install = true
deps =
    -cconstraints.txt
    autopep8
    docformatter

commands =
    autopep8 --verbose --in-place --recursive --aggressive --aggressive {toxinidir}/bobtemplates setup.py
    docformatter --in-place --recursive {toxinidir}/bobtemplates setup.py

[lint]
skip_install = true

deps =
    -cconstraints.txt
    flake8
    # helper to generate HTML reports:
    ; flake8-html
    # Useful flake8 plugins that are Python and Plone specific:
    isort
    flake8-blind-except
    ; flake8-coding
    ; flake8-commas
    flake8-debugger
    flake8-deprecated
    flake8-pep3101
    flake8-plone-api
    flake8-plone-hasattr
    flake8-print
    ; flake8-quotes
    ; flake8-string-format
    flake8-todo
    ; flake8_strict

commands =
    mkdir -p {toxinidir}/_build/reports/flake8
    isort --check-only {toxinidir}/bobtemplates {toxinidir}/package_tests {toxinidir}/skeleton-tests setup.py
    - flake8 --doctests {toxinidir}/bobtemplates {toxinidir}/package_tests {toxinidir}/skeleton-tests setup.py
    flake8 {toxinidir}/bobtemplates {toxinidir}/package_tests {toxinidir}/skeleton-tests setup.py --doctests

allowlist_externals =
    mkdir

[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:black-check]
basepython = python3.10
skip_install = True
deps =
    -cconstraints.txt
    black

commands =
    black --check --diff -v bobtemplates setup.py skeleton-tests package_tests

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

commands =
    black -v bobtemplates setup.py skeleton-tests package_tests

[testenv:docs]
basepython = python3.10
commands =
    sphinx-build -b html -d _build/docs/doctrees docs _build/docs/html -W
#    sphinx-build -b doctest docs _build/docs/doctrees

deps =
    -cconstraints.txt
    Sphinx

[testenv:release]
skip_install = true
basepython = python3.10

deps =
    -cconstraints.txt
    zest.releaser[recommended]

commands =
    python -V
    fullrelease --no-input -v
