# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Maintainer: Daniel M. Capella <polyzen@archlinux.org>

pkgname=python-time-machine
pkgver=3.2.0
pkgrel=2
pkgdesc='Travel through time in your tests'
arch=(x86_64 aarch64)
url='https://github.com/adamchainz/time-machine'
license=(MIT)
depends=(
  python
  python-dateutil
)
makedepends=(
  git
  python-build
  python-installer
  python-setuptools
  python-wheel
)
checkdepends=(
  python-pytest
  python-pytest-randomly
  python-tokenize-rt
  python-freezegun
)
optdepends=(
  'python-pytest: for pytest plugin'
  'python-tokenize-rt: for the migration tool'
)
source=("$pkgname::git+$url#tag=$pkgver")
sha512sums=('e507871c7d1ff87a3ce7d6ac8e90957e3f81c2b3d220b336ec95a38af7ddf622f7d8de4aa61d0a7e20ae543817ec90ae2403a8b5faba34681767903dd0a0825a')
b2sums=('06f66a6682cde59de942d032d14385ff98a8f4d6eddb4e573b7ea96984c36b23d3bdb808dd4a18c5670d8a450791201835f377dbafc0fa2c48aae4935c02c21e')

build() {
  cd "$pkgname"

  python -m build --wheel --no-isolation
}

check() {
  cd "$pkgname"

  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  test-env/bin/python -m pytest -v
}

package() {
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir/usr/share/licenses/$pkgname"
  ln -s "$site_packages/time_machine-$pkgver.dist-info/licenses/LICENSE" \
    "$pkgdir/usr/share/licenses/$pkgname"

  cd "$pkgname"

  python -m installer --destdir="$pkgdir" dist/*.whl
}
