# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Daniel M. Capella <polyzen@archlinux.org>

_name=tzdata
pkgname=python-tzdata
pkgver=2024.1
pkgrel=1
pkgdesc='Provider of IANA time zone data'
arch=(any)
url=https://github.com/python/tzdata
license=(Apache-2.0)
depends=(python)
makedepends=(
  python-build
  python-installer
  python-setuptools
  python-wheel
)
checkdepends=(
  python-pytest
  python-pytest-subtests
)
source=($_name-$pkgver.tar.gz::$url/archive/refs/tags/$pkgver.tar.gz)
sha512sums=('fd021458536e9703b728405e99a8930371c10166d12166aee9708eccbcefa2a3b10974936dcb3f87c8c8875a010238a8d766f6a249955b830b6177c9313e2aac')
b2sums=('f97c175ee3a48b9624b06524f523b62491e373c4d0876278081ba536f2c0201ada3ed23baa4157ecae95b4d95537a0116ce557ba8aa8e4d122f4fbda88a47e28')

build() {
  cd $_name-$pkgver
  python -m build --wheel --skip-dependency-check --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"
  pytest "${pytest_options[@]}"
}

package() {
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl

  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  ln -s /etc/localtime "$pkgdir/$site_packages/$_name/zoneinfo/localtime"
}
