[tox]
# Please note that not all the combinations below are guaranteed to work
# as oldestdeps and devastropy might not support the full python range
# listed here
envlist =
    py{39,310,311,312,313,314}-test{,-alldeps,-oldestdeps,-devdeps}{,-online}{,-cov}
    linkcheck
    codestyle
    build_docs
requires =
    setuptools >= 30.3.0
    pip >= 19.3.1

[testenv]
extras =
    test
    alldeps: all

description =
    run tests
    oldestdeps: with oldest supported dependencies
    devdeps: with development version of dependencies
    cov: determine the code coverage

setenv =
    PYTEST_ARGS = -rsxf --show-capture=no
    online: PYTEST_ARGS = --remote-data=any --reruns=1 --reruns-delay 10 -rsxf --show-capture=no
    devdeps: PIP_EXTRA_INDEX_URL =  https://pypi.anaconda.org/scientific-python-nightly-wheels/simple https://pypi.anaconda.org/liberfa/simple https://pypi.anaconda.org/astropy/simple
    # No astropy py314 wheels on pypi yet
    py314: PIP_EXTRA_INDEX_URL = https://pypi.anaconda.org/liberfa/simple https://pypi.anaconda.org/astropy/simple

deps =
    cov: coverage

    devdeps: numpy>=0.0.dev0
    devdeps: pyerfa>=0.0.dev0
    devdeps: astropy>=0.0.dev0

    oldestdeps: astropy==4.2

    # We set a suitably old numpy along with an old astropy, no need to pick up
    # deprecations and errors due to their unmatching versions
    oldestdeps: numpy==1.20

    online: pytest-rerunfailures

commands =
    pip freeze
    !cov: pytest --pyargs {env:PYTEST_ARGS}
    # Run pytest with coverage to include module imports in report
    # See https://github.com/pytest-dev/pytest-cov/issues/455 for more info
    cov: coverage run -m pytest --pyargs --cov-config={toxinidir}/setup.cfg {env:PYTEST_ARGS}
    cov: coverage xml -o {toxinidir}/coverage.xml

[testenv:linkcheck]
changedir = docs
description = check the links in the HTML docs
extras = docs
commands =
    pip freeze
    sphinx-build -W -b linkcheck . _build/html

[testenv:build_docs]
changedir = docs
description = invoke sphinx-build to build the HTML docs
extras = docs
commands =
    pip freeze
    sphinx-build -W -b html . _build/html

[testenv:codestyle]
skip_install = true
description = check code style
deps = flake8
changedir = {toxinidir}
commands = flake8 pyvo --count
