[tox]
envlist =
    py{39,310}-test{,-alldeps}
    py38-test-devdeps
    py38-cov
    py{39,}-test-numpy{119,120,121,122}
    py38-astropylts
    py39-test-oldestdep-parallels-cov
requires =
    setuptools >= 30.3.0
    pip >= 19.3.1
isolated_build = true

[testenv]
description =
    run tests
    alldeps: with all optional dependencies
    devdeps: with the latest developer version of key dependencies
    cov: and test coverage
    numpy119: with numpy 1.19.*
    numpy120: with numpy 1.20.*
    numpy121: with numpy 1.21.*
    numpy122: with numpy 1.22.*
    numpy123: with numpy 1.23.*
    numpy124: with numpy 1.24.*
    astropylts: with astropy LTS

setenv =
    devdeps: PIP_EXTRA_INDEX_URL = https://pypi.anaconda.org/scientific-python-nightly-wheels/simple

# The following provides some specific pinnings for key packages
deps =
    cov: coverage
    numpy119: numpy==1.19.*
    numpy120: numpy==1.20.*
    numpy121: numpy==1.21.*
    numpy122: numpy==1.22.*
    numpy123: numpy==1.23.*
    numpy124: numpy==1.24.*
    astropylts: astropy==5.0.*
    transformlts: asdf-transform-schemas==0.2.*

    devdeps: -rrequirements-dev.txt
    oldestdeps: minimum_dependencies

    parallel: pytest-xdist
extras =
    test
    alldeps: all
commands_pre=
    devdeps: pip install -U --pre --only-binary :all: -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy

    # Generate `requiremments-min.txt`
    oldestdeps: minimum_dependencies asdf-astropy --filename {envtmpdir}/requirements-min.txt
    # Force install everything from `requirements-min.txt`
    oldestdeps: pip install -r {envtmpdir}/requirements-min.txt

    pip freeze
commands =
    pytest \
    parallel: --numprocesses auto \
    cov: --cov-report xml --cov asdf_astropy
    {posargs}

[testenv:asdf]
changedir={envtmpdir}
allowlist_externals=
    git
    bash
extras=
commands_pre=
    bash -c "pip freeze -q | grep 'asdf-astropy @' > {envtmpdir}/requirements.txt"
    git clone https://github.com/asdf-format/asdf.git
    pip install -e asdf[tests]
    pip install -r {envtmpdir}/requirements.txt
    pip freeze
commands=
    pytest asdf/asdf

[testenv:asdf-standard]
changedir={envtmpdir}
allowlist_externals=
    git
    bash
extras=
commands_pre=
    bash -c "pip freeze -q | grep 'asdf-astropy @' > {envtmpdir}/requirements.txt"
    git clone https://github.com/asdf-format/asdf-standard.git
    pip install -e asdf-standard[test]
    pip install -r {envtmpdir}/requirements.txt
    pip freeze
commands=
    pytest asdf-standard

[testenv:asdf-transform-schemas]
changedir={envtmpdir}
allowlist_externals=
    git
    bash
extras=
commands_pre=
    bash -c "pip freeze -q | grep 'asdf-astropy @' > {envtmpdir}/requirements.txt"
    git clone https://github.com/asdf-format/asdf-transform-schemas.git
    pip install -e asdf-transform-schemas[test]
    pip install -r {envtmpdir}/requirements.txt
    pip freeze
commands=
    pytest asdf-transform-schemas

[testenv:asdf-coordinates-schemas]
changedir={envtmpdir}
allowlist_externals=
    git
    bash
extras=
commands_pre=
    bash -c "pip freeze -q | grep 'asdf-astropy @' > {envtmpdir}/requirements.txt"
    git clone https://github.com/asdf-format/asdf-coordinates-schemas.git
    pip install -e asdf-coordinates-schemas[test]
    pip install -r {envtmpdir}/requirements.txt
    pip freeze
commands=
    pytest asdf-coordinates-schemas

[testenv:specutils]
changedir={envtmpdir}
allowlist_externals=
    git
    bash
extras=
commands_pre=
    bash -c "pip freeze -q | grep 'asdf-astropy @' > {envtmpdir}/requirements.txt"
    git clone https://github.com/astropy/specutils.git
    pip install -e specutils[test]
    pip install -r {envtmpdir}/requirements.txt
    pip freeze
commands=
    pytest specutils

[testenv:gwcs]
changedir={envtmpdir}
allowlist_externals=
    git
    bash
extras=
commands_pre=
    bash -c "pip freeze -q | grep 'asdf-astropy @' > {envtmpdir}/requirements.txt"
    git clone https://github.com/spacetelescope/gwcs.git
    pip install -e gwcs[test]
    pip install -r {envtmpdir}/requirements.txt
    pip freeze
commands=
    pytest gwcs

[testenv:jwst]
deps=
    pytest-xdist
changedir={envtmpdir}
allowlist_externals=
    git
    bash
setenv=
    CRDS_SERVER_URL = https://jwst-crds.stsci.edu
    CRDS_PATH = tmp/crds_cache
    CRDS_CLIENT_RETRY_COUNT = 3
    CRDS_CLIENT_RETRY_DELAY_SECONDS = 20
extras=
commands_pre=
    bash -c "pip freeze -q | grep 'asdf-astropy @' > {envtmpdir}/requirements.txt"
    git clone https://github.com/spacetelescope/jwst.git
    pip install -e jwst[test]
    pip install -r {envtmpdir}/requirements.txt
    pip freeze
commands=
    pytest --numprocesses auto jwst

[testenv:stdatamodels]
changedir={envtmpdir}
allowlist_externals=
    git
    bash
setenv=
    CRDS_SERVER_URL = https://jwst-crds.stsci.edu
    CRDS_PATH = tmp/crds_cache
    CRDS_CLIENT_RETRY_COUNT = 3
    CRDS_CLIENT_RETRY_DELAY_SECONDS = 20
extras=
commands_pre=
    bash -c "pip freeze -q | grep 'asdf-astropy @' > {envtmpdir}/requirements.txt"
    git clone https://github.com/spacetelescope/stdatamodels.git
    pip install -e stdatamodels[test]
    pip install -r {envtmpdir}/requirements.txt
    pip freeze
commands=
    pytest stdatamodels

[testenv:roman_datamodels]
changedir={envtmpdir}
allowlist_externals=
    git
    bash
extras=
commands_pre=
    bash -c "pip freeze -q | grep 'asdf-astropy @' > {envtmpdir}/requirements.txt"
    git clone https://github.com/spacetelescope/roman_datamodels.git
    pip install -e roman_datamodels[test]
    pip install -r {envtmpdir}/requirements.txt
    pip freeze
commands=
    pytest roman_datamodels/tests

[testenv:sunpy]
changedir={envtmpdir}
allowlist_externals=
    git
    bash
extras=
commands_pre=
    bash -c "pip freeze -q | grep 'asdf-astropy @' > {envtmpdir}/requirements.txt"
    git clone https://github.com/sunpy/sunpy.git
    pip install -e sunpy[tests,all]
    pip install -r {envtmpdir}/requirements.txt
    pip freeze
commands=
    pytest sunpy/sunpy/io

[testenv:dkist]
changedir={envtmpdir}
allowlist_externals=
    git
    bash
extras=
commands_pre=
    bash -c "pip freeze -q | grep 'asdf-astropy @' > {envtmpdir}/requirements.txt"
    git clone https://github.com/DKISTDC/dkist.git
    pip install -e dkist[tests]
    pip install -r {envtmpdir}/requirements.txt
    pip freeze
commands=
    pytest dkist
