[tox]
envlist =
    check-{style,security}
    test{,-dev}{,-oldestdeps,-cov}{-jwst,-romancal,-romanisim,-specutils,-dkist,-ndcube}
    docs
requires =
    tox-uv

# tox environments are constructed with so-called 'factors' (or terms)
# separated by hyphens, e.g. test-devdeps-cov. Lines below starting with factor:
# will only take effect if that factor is included in the environment name. To
# see a list of example environments that can be run, along with a description,
# run:
#
#     tox -l -v
#
[main]
jwst_repo = https://github.com/spacetelescope/jwst.git
romancal_repo = https://github.com/spacetelescope/romancal.git
romanisim_repo = https://github.com/spacetelescope/romanisim.git
specutils_repo = https://github.com/astropy/specutils.git
dkist_repo = https://github.com/DKISTDC/dkist.git
ndcube_repo = https://github.com/sunpy/ndcube.git

[testenv:check-style]
description = Run all style and file checks with pre-commit
skip_install = true
deps =
    pre-commit
commands =
    pre-commit install-hooks
    pre-commit run {posargs:--color always --all-files --show-diff-on-failure}

[testenv:docs]
description = invoke sphinx-build to build the HTML docs
extras = docs
commands =
    sphinx-build -W docs docs/_build

[testenv]
description =
    run tests
    jwst: of JWST pipeline
    romancal: of Romancal pipeline
    romanisim: of Romanisim image simulation
    specutils: of Specutils
    dkist: of DKIST
    ndcube: of NDCube
    dev: with the latest developer version of key dependencies
    oldestdeps: with the oldest supported version of key dependencies
    cov: with coverage
    xdist: using parallel processing
allowlist_externals =
    jwst,romancal,romanisim,specutils,dkist,ndcube: git
pass_env =
    HOME
    GITHUB_*
    TOXENV
    CI
    CODECOV_*
    DISPLAY
    CC
    LOCALE_ARCHIVE
    LC_ALL
    jwst,romancal: CRDS_*
    romanisim,romancal: WEBBPSF_PATH
    romanisim: GALSIM_CAT_PATH
    romanisim: FFTW_DIR
    romanisim: LIBRARY_PATH
set_env =
    dev: UV_INDEX = https://pypi.anaconda.org/astropy/simple https://pypi.anaconda.org/liberfa/simple https://pypi.anaconda.org/scientific-python-nightly-wheels/simple
    dev: UV_INDEX_STRATEGY = unsafe-any-match
change_dir =
    jwst,romancal,romanisim,specutils,dkist,ndcube: {env_tmp_dir}
extras =
    test
    alldeps: all
uv_resolution =
    oldestdeps: lowest-direct
deps =
    xdist: pytest-xdist
    cov: pytest-cov
    jwst: jwst[test] @ git+{[main]jwst_repo}
    romancal: romancal[test] @ git+{[main]romancal_repo}
    romanisim: romanisim[test] @ git+{[main]romanisim_repo}
    specutils: specutils[test] @ git+{[main]specutils_repo}
    dkist: dkist[tests] @ git+{[main]dkist_repo}
    ndcube: ndcube[dev] @ git+{[main]ndcube_repo}
    dev: -r requirements-dev.txt
commands_pre =
    {list_dependencies_command}
    jwst: git clone -n --depth=1 --filter=blob:none {[main]jwst_repo} target_repo
    romancal: git clone -n --depth=1 --filter=blob:none {[main]romancal_repo} target_repo
    romanisim: git clone -n --depth=1 --filter=blob:none {[main]romanisim_repo} target_repo
    specutils: git clone -n --depth=1 --filter=blob:none {[main]specutils_repo} target_repo
    dkist: git clone -n --depth=1 --filter=blob:none {[main]dkist_repo} target_repo
    ndcube: git clone -n --depth=1 --filter=blob:none {[main]ndcube_repo} target_repo

    jwst,romancal,romanisim,specutils,dkist,ndcube: git --git-dir={env_tmp_dir}/target_repo/.git checkout HEAD pyproject.toml
commands =
    pytest \
    jwst,romancal,romanisim,specutils,dkist,ndcube: --config-file={env_tmp_dir}/pyproject.toml --pyargs \
    jwst: jwst --ignore-glob=timeconversion --ignore-glob=associations --ignore-glob=scripts --show-capture=no \
    romancal: romancal \
    romanisim: romanisim \
    specutils: specutils \
    dkist: dkist --benchmark-skip \
    ndcube: ndcube \
    xdist: -n auto \
    cov: --cov=. --cov-config=pyproject.toml --cov-report=term-missing --cov-report=xml \
    {posargs}
