# This file encodes a lot of our intended support range, as well as some
# details about dependency availability.
#
# The majority of the information is contained in tox.envlist and testenv.deps.
[tox]
requires =
  tox>=4
envlist =
  # No preinstallations
  py3{9,10,11,12,13}-none
  # Minimum Python
  py39-{min,full}
  # x86 support range
  py3{9,10,11}-{full,pre}-{x86,x64}
  py3{9,10,11}-pre-{x86,x64}
  # x64-only range
  py3{12,13}-{full,pre}-x64
  # Special environment for numpy 2.0-dev testing
  py313-dev-x64
  install
  doctest
  style
  typecheck
skip_missing_interpreters = true

# Configuration that allows us to split tests across GitHub runners effectively
[gh-actions]
python =
  3.9: py39
  3.10: py310
  3.11: py311
  3.12: py312
  3.13: py313

[gh-actions:env]
DEPENDS =
  none: none, install
  pre: pre
  dev: dev
  full: full, install
  min: min

ARCH =
  x64: x64
  x86: x86
  arm64: arm64

[testenv]
description = Pytest with coverage
labels = test
install_command =
  python -I -m pip install -v \
  dev: --only-binary numpy,scipy,h5py \
  !dev: --only-binary numpy,scipy,h5py,pillow,matplotlib \
  pre,dev: --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple \
    {opts} {packages}
pip_pre =
  pre,dev: true
pass_env =
  # getpass.getuser() sources for Windows:
  LOGNAME
  USER
  LNAME
  USERNAME
  # Environment variables we check for
  NIPY_EXTRA_TESTS
  # Pass user color preferences through
  PY_COLORS
  FORCE_COLOR
  NO_COLOR
  CLICOLOR
  CLICOLOR_FORCE
extras = test
deps =
  # General minimum dependencies: pin based on API usage
  # matplotlib 3.5 requires packaging 20
  min: packaging ==20
  min: importlib_resources ==5.12; python_version < '3.12'
  min: typing_extensions ==4.6; python_version < '3.13'
  # NEP29/SPEC0 + 1yr: Test on minor release series within the last 3 years
  # We're extending this to all optional dependencies
  # This only affects the range that we test on; numpy is the only non-optional
  # dependency, and will be the only one to affect pip environment resolution.
  min: numpy ==1.22
  min: h5py ==3.5
  min: indexed_gzip ==1.6
  min: matplotlib ==3.5
  min: pillow ==8.4
  min: pydicom ==2.3
  min: pyzstd ==0.15.2
  min: scipy ==1.8
  # Numpy 2.0 is a major breaking release; we cannot put much effort into
  # supporting until it's at least RC stable
  dev: numpy >=2.1.dev0
  # Scipy stopped producing win32 wheels at py310
  py39-full-x86,x64,arm64: scipy >=1.8
  # Matplotlib depends on scipy, so cannot be built for py310 on x86
  py39-full-x86,x64,arm64: matplotlib >=3.5
  # h5py stopped producing win32 wheels at py39
  {full,pre}-{x64,arm64}: h5py >=3.5
  full,pre,dev: pillow >=8.4
  full,pre: indexed_gzip >=1.6
  full,pre,dev: pyzstd >=0.15.2
  full,pre: pydicom >=2.3
  dev: pydicom @ git+https://github.com/pydicom/pydicom.git@main

commands =
  pytest --doctest-modules --doctest-plus \
    --cov nibabel --cov-report xml:cov.xml \
    --junitxml test-results.xml \
    --durations=20 --durations-min=1.0 \
    --pyargs nibabel {posargs:-n auto}

[testenv:install]
description = Install and verify import succeeds
labels = test
deps =
extras =
install_command = python -I -m pip install {opts} {packages}
commands =
  python -c "import nibabel; print(nibabel.__version__)"

[testenv:docs]
description = Build documentation site
labels = docs
allowlist_externals = make
extras = doc
commands =
  make -C doc html

[testenv:doctest]
description = Run doctests in documentation site
labels = docs
allowlist_externals = make
extras =
  doc
  test
commands =
  make -C doc doctest

[testenv:style]
description = Check our style guide
labels = check
deps =
  ruff>=0.3.0
skip_install = true
commands =
  ruff check --diff nibabel
  ruff format --diff nibabel

[testenv:style-fix]
description = Auto-apply style guide to the extent possible
labels = pre-release
deps =
  ruff
skip_install = true
commands =
  ruff check --fix nibabel
  ruff format nibabel

[testenv:spellcheck]
description = Check spelling
labels = check
deps =
  codespell[toml]
skip_install = true
commands =
  codespell . {posargs}

[testenv:typecheck]
description = Check type consistency
labels = check
deps =
  mypy
  pytest
  types-setuptools
  types-Pillow
  pydicom
  numpy
  pyzstd
  importlib_resources
  typing_extensions
skip_install = true
commands =
  mypy nibabel

[testenv:build{,-strict}]
labels =
  check
  pre-release
deps =
  build
  twine
skip_install = true
set_env =
  build-strict: PYTHONWARNINGS=error
commands =
  python -m build
  python -m twine check dist/*

[testenv:publish]
depends = build
labels = release
deps =
  twine
skip_install = true
commands =
  python -m twine upload dist/*

[testenv:zenodo]
deps = gitpython
labels = pre-release
skip_install = true
commands =
  python tools/prep_zenodo.py
