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

pkgname=python-time-machine
pkgver=2.16.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'
)
optdepends=('python-pytest: for pytest plugin')
source=("$pkgname::git+$url#tag=$pkgver")
b2sums=('800fd97077b62497eac4378d732ff32dfde9b16261237ded7cb55452b4d11acd44ade247a56749e8cd05165ada0c464130f14a18319172d5b8d33d5c52c8cad5')

build() {
  cd "$pkgname"

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

check() {
  cd "$pkgname"

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

  # install to temporary directory
  python -m installer --destdir="$(pwd)/tmp_install" dist/*.whl

  PYTHONPATH="$(pwd)/tmp_install$site_packages" \
    pytest -v
}

package() {
  cd "$pkgname"

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

  # symlink license file
  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/LICENSE" \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
