[tox]
requires =
  tox>=4
envlist =
  py3{10,11,12,13}-{latest,pre}
  py310-min
skip_missing_interpreters = true

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

[gh-actions:env]
DEPENDS =
  min: min
  latest: latest
  pre: pre

[testenv]
description = Pytest with coverage
labels = test
pip_pre =
  pre: true
pass_env =
  # getpass.getuser() sources for Windows:
  LOGNAME
  USER
  LNAME
  USERNAME
  # Pass user color preferences through
  PY_COLORS
  FORCE_COLOR
  NO_COLOR
  CLICOLOR
  CLICOLOR_FORCE
  PYTHON_GIL
deps =
  py313: traits @ git+https://github.com/enthought/traits.git@10954eb
extras = test
setenv =
  pre: PIP_EXTRA_INDEX_URL=https://pypi.anaconda.org/scientific-python-nightly-wheels/simple
  pre: UV_INDEX=https://pypi.anaconda.org/scientific-python-nightly-wheels/simple
  pre: UV_INDEX_STRATEGY=unsafe-best-match
uv_resolution =
  min: lowest-direct

commands_pre =
  # Use py* to disable for other environments
  py3{10,11,12,13}: python scripts/fetch_templates.py
commands =
  pytest --cov-report term-missing --durations=20 --durations-min=1.0 {posargs:-n auto}

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

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

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

[testenv:build{,-strict}]
labels =
  check
  pre-release
deps =
  build
  twine
skip_install = true
set_env =
  # Ignore specific known warnings:
  # https://github.com/pypa/pip/issues/11684
  # https://github.com/pypa/pip/issues/12243
  strict: PYTHONWARNINGS=error,once:pkg_resources is deprecated as an API.:DeprecationWarning:pip._internal.metadata.importlib._envs,once:Unimplemented abstract methods {'locate_file'}:DeprecationWarning:pip._internal.metadata.importlib._dists
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/*
