# This is a configuration file for tox, used to test
# Biopython on various versions of Python etc under
# the Travis Continuous Integration service which is
# configured in the file .travis.yml
#
# By default tox will look for tox.ini, so this file
# will not conflict with any personal tox setup.
#
# You can explicitly use this tox configuration on your
# own machine (via the -c setting), PROVIDED you have
# all the relevant versions of Python installed. e.g.
# specifying a specific target envronment (via -e):
#
# $ pip install tox
# $ tox -c .travis-tox.ini -e py35-nocov
#
# Or with test coverage:
#
# $ pip install tox coverage
# $ tox -c .travis-tox.ini -e py35-cover
#
# Or to run the pep8/flake8 etc Python coding style checks:
#
# $ pip install tox flake8 pydocstyle restructuredtext_lint
# $ tox -c .travis-tox.ini -e style
#
# See the envlist setting for other valid arguments.

[tox]
minversion = 2.0
skipsdist = True
envlist =
    style
    flake8
    sdist
    bdist_wheel
    api
    {py36,py37,py38,pypy3}-cover
    {py36,py37,py38,pypy3}-nocov

[testenv]
# TODO: Try tox default sdist based install instead:
skip_install = True
sitepackages = True
passenv =
    CI
    TRAVIS
    TRAVIS_*
    TOXENV
    CODECOV_*
    HOME_4_TCOFFEE
whitelist_externals =
    bash
    echo
# Want to avoid overhead of compiling numpy or scipy:
# (But must compile numpy for PyPy right now)
install_command = pip install --only-binary=scipy {opts} {packages}
deps =
    setuptools
    wheel
    py36,py37,py38: numpy
    pypy3: numpy<1.18.0
    #Lines startings xxx: are filtered by the environment.
    #Leaving py36 without any dependencies (except numpy)
    cover: coverage
    cover: codecov
    py37: mmtf-python
    # https://bitbucket.org/rptlab/reportlab/issues/176/incompatibility-with-pillow-600
    py38: reportlab
    py38: pillow==5.4
    py37: psycopg2-binary
    py37: mysql-connector-python-rf
    py37: mysqlclient
    py38: rdflib
    pypy3: mysqlclient
    py37: scipy
    py38: networkx
    py37: matplotlib
commands =
    #The bash call is a work around for special characters
    #The /dev/null is to hide the verbose output but leave warnings
    bash -c \'python setup.py install > /dev/null\'
    #The bash call is a work around for the cd command
    nocov: bash -c \'cd Tests && python run_tests.py --offline\'
    #See https://codecov.io/ and https://github.com/codecov/example-python
    cover: bash -c \'rm -rf Tests/coverage.xml\'
    cover: bash -c \'cd Tests && coverage run run_tests.py --offline && coverage xml\'
    cover: codecov --file Tests/coverage.xml -X pycov -X gcov

[testenv:style]
# This does not need to install Biopython or any of its dependencies
skip_install = True
whitelist_externals =
    black
    bash
deps =
    black==19.10b0
commands =
    # Now do various checks on our RST files:
    # Check sort order (bash call work around for pipe character)
    bash -c \'grep "^- " CONTRIB.rst | LC_ALL=C sort -u -c -f\'
    # Check copyright date
    bash -c \'grep "1999-`date +'%Y'`" LICENSE.rst\'
    # Check no __docformat__ lines
    bash -c "if grep --include '*.py' -rn '^__docformat__ ' Bio BioSQL Tests Scripts Doc ; then echo 'Remove __docformat__ line(s), we assume restructuredtext.'; false; fi"
    # Black style check:
    black --check --diff .

[testenv:sdist]
# This does not need to install Biopython or any of its dependencies
skip_install = True
deps =
commands =
    python setup.py sdist --formats=gztar,zip

[testenv:bdist_wheel]
# This should not require NumPy while compiling our C code...
skip_install = True
deps =
commands =
    python setup.py bdist_wheel

[testenv:api]
# Note Sphinx likes to have the code installed so can import it
skip_install = False
whitelist_externals =
    bash
    sphinx-apidoc
    make
deps =
    mmtf-python
    mysql-connector-python-rf
    numpy
    rdflib
    reportlab
    scipy
    sphinx>=1.8.0
    numpydoc==1.0.0
    pygments
    sphinx_rtd_theme
commands =
    bash -c \'python setup.py install > /dev/null\'
    make -C Doc/api/ html
