[tox]
minversion = 4.0
envlist = test

[helpers]
functions =
	bash --noprofile --norc -eo pipefail -c ' \
		. ./plover_build_utils/functions.sh; \
		python=python; \
		"$@"'
# If `-e` is present in the arguments, call pip directly,
# otherwise, use `plover_build_utils.install_wheels`.
install_command =
	{envpython} -c 'import subprocess, sys; \
		from plover_build_utils.install_wheels import WHEELS_CACHE, install_wheels; \
		args = sys.argv[1:]; \
		subprocess.check_call([sys.executable, "-m", "pip", \
				       "install", "--no-build-isolation", \
				       "-f", WHEELS_CACHE] + args) \
		if "-e" in args else \
		install_wheels(args)'

# Default, Python 3 based, environment.
[testenv]
envdir = {toxworkdir}/dev
extras =
	gui_qt
	log
deps =
	-c	reqs/constraints.txt
	-r	reqs/bootstrap.txt
	-r	reqs/build.txt
	-r	reqs/ci.txt
	-r	reqs/dist.txt
	-r	reqs/dist_extra_gui_qt.txt
	-r	reqs/dist_extra_log.txt
	-r	reqs/packaging.txt
	-r	reqs/release.txt
	-r	reqs/setup.txt
	-r	reqs/test.txt
install_command = {[helpers]install_command} {packages}
list_dependencies_command = {envpython} -m pip freeze --all
allowlist_externals = bash
passenv =
	MACOSX_DEPLOYMENT_TARGET
setenv =
	SSL_CERT_FILE={envsitepackagesdir}/certifi/cacert.pem

# Lightweight tests only environments.
[testenv:py3{,6,7,8,9,10,11,12,13}]
description = run tests using {envname}
base_python = {envname}
envdir = {toxworkdir}/{envname}
extras =
	gui_qt
deps =
	-c	reqs/constraints.txt
	-r	reqs/bootstrap.txt
	-r	reqs/dist.txt
	-r	reqs/setup.txt
	-r	reqs/test.txt
setenv =
	{[testenv:test]setenv}
commands =
	{envpython} -m pytest {posargs}

[testenv:launch]
description = launch plover
usedevelop = true
passenv =
	{[testenv]passenv}
	DISPLAY
	XDG_RUNTIME_DIR
commands =
	{envpython} setup.py launch -- {posargs}

[testenv:packaging_checks]
description = packaging sanity checks
setenv =
	PIP_FIND_LINKS={toxinidir}/.cache/wheels
commands =
	{[helpers]functions} -- packaging_checks {posargs}

[testenv:plugins_install]
description = install specified plugins
usedevelop = true
commands =
	{[helpers]install_command} {posargs}

[testenv:release_{prepare,finalize}]
description = prepare/finalize a release
passenv = *
commands =
	{[helpers]functions} -- {envname} {posargs}

[testenv:setup]
description = run a `setup.py` command
commands =
	{envpython} setup.py {posargs}

[testenv:test]
description = run tests
setenv =
	QT_QPA_PLATFORM=offscreen
commands =
	{envpython} -m pytest {posargs}

# vim: ft=cfg list
