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

_name=tzdata
pkgname=python-tzdata
pkgver=2025.2.post0
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=('f4e4442ee6dfa48ae2d3ee1efb1e9919838cc05867dc3121877d0a3df35121ad3b1d12a02941e9587684205f6513d04a2a547184e81af92b810d474667918080')
b2sums=('4407343c180578ba4e49a3027a4905c17bfe4ffb815fe94f24cea9374ef511c79adcce3d10f51bc4ae7bde76f5c2e53f9de2cd3fe1e218dfafd3b655b60efaec')

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"
}
