; tox configuration file for running tests similar to buildbot builders.
;
; The main trial based environments are defined based on a set of tags. Each
; tag will trigger a different behavior. Multiple tags can be set for the same environment:
;
; * alldeps - install all possible dependencies.
; * nodeps - avoid installing any dependency.
; * withcov - run the tests wrapped using the coverage.
; * nocov - run the tests directly, without using the coverage wrapper.
; * wheel - build the wheel distribution
; * posix - prepare the tests to be run in a Linux/Unix/macOS environment.
; * macos - prepare the tests to be run in a OS X 10.11+ environment (superset of posix)
; * macos1010 - prepare the tests to be run in a OS X 10.10 environment (superset of posix)
; * windows - prepare the tests to be executed under Windows.
;
; Some tags are defined only while transitioning to an updated Buildbot and
; should be removed after the transition.
; See: https://github.com/twisted-infra/braid/issues/222
;
; * tests - similar to alldeps
; * coverage - similar to withcov and alldeps
; * nomodules - similar to nodeps
;
; There is a non-default `codecov-publish` environment used to publish the
; coverage results to codecov.io. It should be called after running the
; standard coverage environment.
;
; A non-default `txchecker-travis` environment is used to run twistedchecker
; on travis in --diff mode
;
[tox]
minversion=2.4
skip_missing_interpreters=True
toxworkdir=build/
envlist=
    {py27,py33,py34,py35,py36}-{alldeps,nodeps}-{withcov,nocov}-{posix,macos,macos1010,windows}
    {py27,py36}-wheel
    pyflakes,twistedchecker,apidocs,narrativedocs,newsfragment,manifest-checker


[testenv]
;; dependencies managed by extras in t.p._setup.py._EXTRAS_REQUIRE
extras =
    {alldeps,tests,coverage}: all_non_platform

    windows: windows_platform

    {alldeps,tests}-macos: osx_platform

    ; Documentation
    narrativedocs: dev

;; dependencies that are not specified as extras
deps =
    py27-{alldeps,tests,coverage}-{posix,macos}: pysqlite

    {withcov,coverage}: coverage

    codecov-publish: codecov==2.0.5

    wheel: wheel

    ; Code quality checkers
    pyflakes{,3}: pyflakes
    manifest-checker: check-manifest

    {twistedchecker,txchecker-travis}: twistedchecker>=0.7.1
    txchecker-travis: diff_cover

; All environment variables are passed.
passenv = *

setenv =
   ; Enable sub-processes coverage reports and store coverage reports in a
   ; known location.
   COVERAGE_PROCESS_START = {toxinidir}/.coveragerc
   COVERAGE_FILE = {toxinidir}/.coverage
   # Help tests know where the base directory is.
   TOX_INI_DIR = {toxinidir}

   ; Skip twistedchecker warnings that are not yet required in the required run
   txchecker-travis-required: TWISTEDCHECKER_SKIP_WARNINGS = W9208,C0302

commands =
    ;
    ; Display information about Python interpreter
    ; which will be used in subsequent steps
    ;
    python -c "import sys; print(sys.prefix)"
    python -c "import sys; print(sys.exec_prefix)"
    python -c "import sys; print(sys.executable)"
    python --version

    ; Install PyDoctor here so it DOESNT overwrite Twisted
    py27-{alldeps,tests}: pip install --no-deps epydoc pydoctor
    apidocs: pip install --no-deps epydoc pydoctor

    ; Run tests without wrapping them using coverage.
    {nocov,nomodules,tests}: python -m twisted.trial --reactor={env:TWISTED_REACTOR:default} --reporter={env:TRIAL_REPORTER:verbose}  {posargs:twisted}

    ; Run the tests wrapped using coverage.
    {withcov,coverage}: python {toxinidir}/admin/_copy.py {toxinidir}/admin/zz_coverage.pth {envsitepackagesdir}/zz_coverage.pth
    {withcov,coverage}: coverage erase
    {withcov,coverage}: coverage run -p --rcfile={toxinidir}/.coveragerc -m twisted.trial --reactor={env:TWISTED_REACTOR:default} --reporter={env:TRIAL_REPORTER:verbose} {posargs:twisted}

    ; Publish the coverage reports to codecov.io
    codecov-publish: coverage combine
    codecov-publish: coverage xml -o coverage.xml -i
    codecov-publish: codecov {env:CODECOV_OPTIONS:} -X search -X gcov -f coverage.xml

    ; Build in a root folder so that buildbot can pick the result
    wheel: python setup.py bdist_wheel --dist-dir {toxinidir}/dist

    twistedchecker: twistedchecker src/{posargs:twisted}
    txchecker-travis: {toxinidir}/.travis/twistedchecker-trunk-diff.sh {posargs:twisted}

    pyflakes: pyflakes {posargs:src/twisted admin bin}
    pyflakes3: /bin/sh -c "pyflakes $(find src/twisted admin bin \! -name "compat.py" \! -name "test_compat.py" \! -name "dict.py"  -name '*.py' -o -name '*.3only')"

    apidocs: {toxinidir}/bin/admin/build-apidocs {toxinidir}/src/ apidocs
    narrativedocs: sphinx-build -aW -b html -d {toxinidir}/docs/_build {toxinidir}/docs {toxinidir}/docs/_build/

    newsfragment: python {toxinidir}/bin/admin/check-newsfragment "{toxinidir}"

    manifest-checker: check-manifest --ignore "docs/_build*,docs/historic/*,admin*,bin/admin*,twisted/topfiles/*.Old"

[testenv:twistedchecker]
basepython=python3.6
[testenv:pyflakes]
basepython=python2.7
[testenv:pyflakes3]
basepython=python3.6
[testenv:apidocs]
basepython=python2.7
[testenv:newsfragment]
basepython=python2.7
[testenv:manifest-checker]
basepython=python2.7

# TwistedChecker needs to be 3.5
[testenv:txchecker-travis-required]
basepython=python3.5
usedevelop=True
[testenv:txchecker-travis-all]
basepython=python3.5
usedevelop=True
