# Maintainer:
# Contributor: Felix Yan <felixonmars@archlinux.org>
# Contributor: Thomas Weißschuh <thomas t-8ch.de>
# Contributor: George Brooke <george+arch.aur@george-brooke.co.uk>
# Contributor: Sebastian Wiesner <lunaryorn googlemail com>

_name=tox
pkgname=python-tox
pkgver=4.23.2
pkgrel=2
pkgdesc='Python virtualenv management and testing tool'
arch=('any')
url='https://tox.readthedocs.io'
license=('GPL2')
depends=(
  'python'
  'python-cachetools'
  'python-chardet'
  'python-colorama'
  'python-filelock'
  'python-packaging'
  'python-platformdirs'
  'python-pluggy'
  'python-pyproject-api'
  'python-virtualenv'
)
makedepends=(
  'python-build'
  'python-hatch-vcs'
  'python-hatchling'
  'python-installer'
  'python-wheel'
)
checkdepends=(
  # 'python-devpi-process'  # NOTE: pulls in devpi-{client,server}
  'python-diff-cover'
  'python-distlib'
  'python-flaky'
  'python-pytest'
  'python-pytest-mock'
  'python-psutil'
  'python-re-assert'
  # 'python-time-machine'  # NOTE: needed?
)
optdepends=(
  'python-pytest: for pytest plugin to test tox and its plugins'
  'python-pytest-mock: for pytest plugin to test tox and its plugins'
  'python-re-assert: for pytest plugin to test tox and its plugins'
)
source=(https://files.pythonhosted.org/packages/source/${_name::1}/$_name/$_name-$pkgver.tar.gz)
sha512sums=('5008964ebed3c94a6ad5f0985150c7bf73fd3996b91171b16323d195bf0288102aac0dc38848bd4c63e5c5678ab1a82c170579139eda97132a4555eb11d381a0')
b2sums=('776b653388a4b0578b5e5fd7957e97e1b3591d6239a23fe232238a7ce64a9adc641bbd5d3d4585ebb094da7c487da2b0875a466d62e27a9686317cc38a9b2491')

prepare() {
  find $_name-$pkgver -name "*.pyc" -delete
}

build() {
  cd $_name-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  local pytest_options=(
    -vv
  )
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_name-$pkgver
  # install to temporary location, as importlib is used
  python -m installer --destdir=test_dir dist/*.whl
  export PYTHONPATH="$PWD/test_dir/$site_packages:$PYTHONPATH"
  # TODO: package remaining checkdepends
  # pytest "${pytest_options[@]}"
}

package() {
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  # add legacy symlink
  ln -sv tox "$pkgdir"/usr/bin/tox3
}
