# Maintainer: David Runge <dvzrv@archlinux.org>

_name=pendulum
pkgname=python-pendulum
pkgver=3.0.0
pkgrel=1
pkgdesc="Python datetimes made easy"
arch=(x86_64 aarch64)
url="https://pendulum.eustace.io/"
_url="https://github.com/sdispater/pendulum"
license=(MIT)
depends=(
  gcc-libs
  glibc
  python
  python-dateutil
  python-tzdata
  python-time-machine
)
makedepends=(
  python-build
  python-installer
  python-maturin
  python-wheel
)
checkdepends=(
  python-babel
  python-freezegun
  python-pytest
  python-pytz
  python-pytzdata
)
source=($pkgname-$pkgver.tar.gz::$_url/archive/$pkgver.tar.gz)
sha512sums=('f4cab40bec00029ccda44f15c71cf07a4518b6d86570b2f3425db2e3bb96151b22aa5065b1e21cc4b2b0cfef216f6af1ae6a16eb4efdb811dbdb18a7eab6c24a')
b2sums=('5cbf0e2e504964e75c45ad41fcdab5a2ef0be91d9f4a8898305d15a5dc124abc3dc0986c7559d45091325bf4819f5e854ce87f92d534b24d1ac8c0852097df09')

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"
  pytest "${pytest_options[@]}"
}

package() {
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 {CHANGELOG.md,README.rst} -t "$pkgdir/usr/share/doc/$pkgname/"
  install -vDm 644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
}
