[tox]
min_version = 4.0
requires =
    tox-pypi-filter>=0.14
envlist =
    py{312,313,314}{,-online,-minimal}
    py314-devdeps
    py312-oldestdeps
    codestyle
    build_docs{,-gallery}
    py312-figure{,-devdeps}
    core_deps
    linkcheck

[testenv]
pypi_filter = file://{toxinidir}/.test_package_pins.txt
allowlist_externals=
    /bin/sh
# Run the tests in a temporary directory to make sure that we don't import sunpy from the source tree
changedir = .tmp/{envname}
description =
    run tests
    conda: with the latest conda version of key dependencies
    devdeps: with the latest developer version of key dependencies
    figure: runs the figure test suite.
    oldestdeps: with the oldest supported version of key dependencies
    online: that require remote data (as well as the offline ones)
    reportlog: runs with --report-log pytest-log.jsonl for creating issues from cron runs
    noana: Skip building the ANA C extension
pass_env =
    # A variable to tell tests we are on a CI system
    CI
    # Custom compiler locations (such as ccache)
    CC
    # Location of locales (needed by sphinx on some systems)
    LOCALE_ARCHIVE
    # If the user has set a LC override we should follow it
    LC_ALL
setenv =
    MPLBACKEND = agg
    SUNPY_SAMPLEDIR = {env:SUNPY_SAMPLEDIR:{toxinidir}/.tox/sample_data/}
    devdeps,build_docs,online: HOME = {envtmpdir}
    noana: SUNPY_NO_BUILD_ANA_EXTENSION=1
    PARFIVE_HIDE_PROGRESS = True
    NO_VERIFY_HELIO_SSL = 1
    devdeps: PIP_EXTRA_INDEX_URL = https://pypi.anaconda.org/astropy/simple https://pypi.anaconda.org/scientific-python-nightly-wheels/simple https://pypi.anaconda.org/liberfa/simple
deps =
    # Avoid adding this to the pyproject.toml as a dependency
    pytest-xdist
    # devdeps is intended to be used to install the latest developer version of key dependencies.
    # For packages which publish nightly wheels this will pull the latest nightly
    devdeps: astropy>=0.0.dev0
    devdeps: matplotlib>=0.0.dev0
    devdeps: numpy>=0.0.dev0
    devdeps: pandas>=0.0.dev0
    devdeps: pluggy>=0.0.dev0
    devdeps: pyerfa>=0.0.dev0
    devdeps: pytest>=0.0.dev0
    devdeps: scikit-image>=0.0.dev0
    devdeps: reproject>=0.0.dev0
    # Packages without nightly wheels will be built from source like this
    devdeps: git+https://github.com/asdf-format/asdf
    devdeps: git+https://github.com/astropy/asdf-astropy
    devdeps: git+https://github.com/Cadair/parfive
    devdeps: git+https://github.com/MAVENSDC/cdflib
    devdeps: git+https://github.com/sunpy/mpl-animators
    # Handle minimum dependencies via minimum_dependencies
    oldestdeps: minimum_dependencies
    # Figure tests need a tightly controlled environment
    figure-!devdeps: astropy==7.0.2
    figure-!devdeps: matplotlib==3.8.2
    figure-!devdeps: mpl-animators==1.2.1
    # Use pytest-reportlog
    reportlog: pytest-reportlog
extras =
    !minimal: tests
    minimal: core,tests-only
commands_pre =
    oldestdeps: minimum_dependencies sunpy --extras asdf dask image jpeg2000 map opencv net scikit-image spice timeseries visualization tests-only --filename requirements-min.txt
    oldestdeps: pip install -r requirements-min.txt
    oldestdeps: python -c "import astropy.time; astropy.time.update_leap_seconds()"
    pip freeze --all --no-input
commands =
    figure: /bin/sh -c "mkdir -p ./figure_test_images; python -c 'import matplotlib as mpl; print(mpl.ft2font.__file__, mpl.ft2font.__freetype_version__, mpl.ft2font.__freetype_build_type__)' > ./figure_test_images/figure_version_info.txt"
    figure: /bin/sh -c "pip freeze >> ./figure_test_images/figure_version_info.txt"
    figure: /bin/sh -c "cat ./figure_test_images/figure_version_info.txt"
    figure: python -c "import sunpy.tests.helpers as h; print(h.get_hash_library_name())"
    pytest \
    -vvv \
    -r fEs \
    --pyargs sunpy \
    --cov-report=xml \
    --cov=sunpy \
    --cov-config={toxinidir}/.coveragerc \
    {toxinidir}/docs \
    online: --hypothesis-show-statistics \
    online: --remote-data=any \
    figure: -m "mpl_image_compare" \
    figure: --mpl \
    figure: --remote-data=any \
    figure: --mpl-generate-summary=html \
    figure: --mpl-baseline-path=https://raw.githubusercontent.com/sunpy/sunpy-figure-tests/sunpy-main/figures/{envname}/ \
    reportlog: --report-log pytest-log.jsonl
    {posargs}

[testenv:build_docs{,-gallery}]
changedir = docs
description = Invoke sphinx-build to build the HTML docs
extras =
    all
    docs
    gallery: docs-gallery
commands =
    pip freeze --all --no-input
    sphinx-build \
    -j auto \
    --color \
    -W \
    --keep-going \
    -b html \
    -d _build/.doctrees \
    . \
    _build/html \
    !gallery: -D plot_gallery=0 \
    {posargs}
    python -c 'import pathlib; print("Documentation available under file://\{0\}".format(pathlib.Path(r"{toxinidir}") / "docs" / "_build" / "index.html"))'

[testenv:linkcheck]
changedir = docs
description = Invoke sphinx-build to check the URLS within the docs
extras =
    all
    docs
commands =
    pip freeze --all --no-input
    sphinx-build \
    -qqq \
    --color \
    -b linkcheck \
    -D plot_gallery=0 \
    . \
    _build/html \
    {posargs}

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

[testenv:coordinates]
description = Run sunpy.coordinates specific tests with full functionality
commands =
    pytest \
    --pyargs sunpy.coordinates \
    --remote-data=any \
    {posargs}
