[tox]
env_list =
    compatibility
    mocks3
    coverage
    py{39,310,311,312,313}{,-compatibility,-coverage,-jsonschema}{,-devdeps}{,-parallel}{,-pytestdev}
    asdf{-standard,-transform-schemas,-unit-schemas,-wcs-schemas,-coordinates-schemas,-astropy,-zarr,-compression}
    astrocut
    gwcs
    jwst
    stdatamodels
    stpipe
    roman_datamodels
    weldx
    sunpy
    dkist

[testenv]
set_env =
    devdeps: PIP_EXTRA_INDEX_URL = https://pypi.anaconda.org/scientific-python-nightly-wheels/simple
    devdeps: ASDF_UNSTABLE_CORE_SCHEMAS = 1
deps =
    compatibility: virtualenv
    coverage: coverage
    devdeps: -rrequirements-dev.txt
    numpydev: cython
    oldestdeps: minimum_dependencies
    parallel: pytest-xdist
    pytestdev: git+https://github.com/pytest-dev/pytest
    mocks3: moto[s3,server]
    mocks3: boto
    mocks3: fsspec
    mocks3: s3fs
extras = all,tests
# astropy will complain if the home directory is missing
pass_env = HOME
package = editable
commands_pre =
    python -m pip install --upgrade pip

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

    pip freeze
# print out the default core schemas version
    python -c "import asdf; print(f'Core schemas default version: {asdf.get_config().default_version}')"
commands =
# coverage run must be used because the pytest-asdf plugin will interfere
# with proper coverage measurement due to the order pytest loads its
# entry points.
    coverage: coverage run --source=asdf --rcfile={tox_root}/pyproject.toml -m \
    pytest \
    devdeps: -W "ignore::asdf_standard.exceptions.UnstableCoreSchemasWarning"
    compatibility: integration_tests/compatibility/ \
    mocks3: integration_tests/mocks3/ \
    --remote-data \
    --durations=10 \
    jsonschema: --jsonschema \
    parallel: --numprocesses auto \
# the OpenAstronomy workflow appends `--cov-report` in `{posargs}`, which `coverage` doesn't recognize
    !coverage: {posargs}
    coverage:
    coverage: coverage xml -o {tox_root}/coverage.xml
    coverage: coverage report

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[testenv:weldx]
change_dir = {env_tmp_dir}
allowlist_externals =
    git
    bash
extras =
commands_pre =
    bash -c "pip freeze -q | grep 'asdf @' > {env_tmp_dir}/requirements.txt"
    git clone https://github.com/BAMWelDX/weldx.git
    pip install -e weldx[test,media]
    pip install -r {env_tmp_dir}/requirements.txt
    pip freeze
commands =
    pytest weldx/weldx/tests/asdf_tests weldx/weldx/schemas --asdf-tests

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

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

[testenv:abacusutils]
change_dir = {env_tmp_dir}
allowlist_externals =
    git
    bash
extras =
commands_pre =
    bash -c "pip freeze -q | grep 'asdf @' > {env_tmp_dir}/requirements.txt"
    git clone https://github.com/abacusorg/abacusutils.git
    pip install -e ./abacusutils pytest
    pip install -r {env_tmp_dir}/requirements.txt
# make an empty pytest.ini to prevent pytest from crawling up
# one directory and finding the pytest configuration for the asdf
# repo clone
    bash -c "echo '' > pytest.ini"
    pip freeze
commands =
# only running a subset of tests since only a portion of abacusutils
# relies on asdf
    pytest abacusutils/tests/test_data.py
