[tox]
envlist = py36, py37, examples, notebooks, flake8, docs, coverage, benchmarks

[travis]
python =
    3.7: py37
    3.6: py36

[flake8]
max-line-length = 120
ignore = E121 E126 E123 E128 E133 E226 E241 E242 E704 W291 W293 W391 W503 W504 W505

[testenv:flake8]
basepython = python
passenv = DISPLAY
deps =
    -r{toxinidir}/requirements_dev.txt
    -r{toxinidir}/requirements_continuous_integration.txt
commands =
    flake8 flatland tests examples benchmarks

[testenv:docs]
basepython = python
whitelist_externals = make
passenv =
    DISPLAY
    HTTP_PROXY
    HTTPS_PROXY
deps =
    -r{toxinidir}/requirements_dev.txt
    -r{toxinidir}/requirements_continuous_integration.txt
commands =
    make docs

[testenv:coverage]
basepython = python
whitelist_externals = make
passenv =
    DISPLAY
; HTTP_PROXY+HTTPS_PROXY required behind corporate proxies
    HTTP_PROXY
    HTTPS_PROXY
deps =
    -r{toxinidir}/requirements_dev.txt
    -r{toxinidir}/requirements_continuous_integration.txt
commands =
    make coverage

[testenv:benchmarks]
basepython = python
setenv =
    PYTHONPATH = {toxinidir}
passenv =
    DISPLAY
; HTTP_PROXY+HTTPS_PROXY required behind corporate proxies
    HTTP_PROXY
    HTTPS_PROXY
whitelist_externals = sh
deps =
    -r{toxinidir}/requirements_dev.txt
    -r{toxinidir}/requirements_continuous_integration.txt
commands =
    sh -c 'ls benchmarks/*.py  | xargs -n 1 python'

[testenv:examples]
basepython = python
setenv =
    PYTHONPATH = {toxinidir}
passenv =
    DISPLAY
    XAUTHORITY
; HTTP_PROXY+HTTPS_PROXY required behind corporate proxies
    HTTP_PROXY
    HTTPS_PROXY
whitelist_externals = sh
deps =
    -r{toxinidir}/requirements_dev.txt
commands =
    sh -c 'echo DISPLAY=$DISPLAY'
    sh -c 'echo XAUTHORITY=$XAUTHORITY'
; pipe echo into python since some examples expect input to close the window after the example is run
    sh -c 'ls examples/*.py | xargs -I{} -n 1 sh -c "echo -e \"\n====== Running {} ========\n\"; echo "q" | python {}"'

[testenv:notebooks]
basepython = python
setenv =
    PYTHONPATH = {toxinidir}
passenv =
    DISPLAY
    XAUTHORITY
; HTTP_PROXY+HTTPS_PROXY required behind corporate proxies
    HTTP_PROXY
    HTTPS_PROXY
whitelist_externals = sh
deps =
    -r{toxinidir}/requirements_dev.txt
    -r{toxinidir}/requirements_continuous_integration.txt
commands =
    sh -c 'jupyter nbextension enable --py --sys-prefix widgetsnbextension'
    sh -c 'jupyter nbextension enable --py --sys-prefix jpy_canvas'
; https://stackoverflow.com/questions/35545402/how-to-run-an-ipynb-jupyter-notebook-from-terminal/35545463
    sh -c 'ls notebooks/*.ipynb  | xargs -n 1 jupyter nbconvert --to python'
    sh -c 'ls notebooks/*.py  | xargs -I{} -n 1 sh -c "echo -e \"\n====== Running {} ========\n\"; ipython {}"'

[testenv]
whitelist_externals = sh
                      pip
setenv =
    PYTHONPATH = {toxinidir}
passenv =
    DISPLAY
; HTTP_PROXY+HTTPS_PROXY required behind corporate proxies
    HTTP_PROXY
    HTTPS_PROXY
deps =
    -r{toxinidir}/requirements_dev.txt
commands =
    sh -c 'echo DISPLAY: $DISPLAY'
    py.test --basetemp={envtmpdir}