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

_name=dirty-equals
pkgname=python-dirty-equals
pkgver=0.7.1.post0
_pkgver=${pkgver/%.post0/-post0}
pkgrel=1
pkgdesc="Doing dirty (but extremely useful) things with equals"
arch=(any)
url="https://github.com/samuelcolvin/dirty-equals"
license=(MIT)
depends=(
  python
  python-pytz
)
makedepends=(
  python-build
  python-hatchling
  python-installer
)
checkdepends=(
  python-packaging
  python-pydantic
  python-pytest
  python-pytest-examples
  python-pytest-mock
)
optdepends=(
  'python-pydantic: for pydantic support'
)
source=($pkgname-$pkgver.tar.gz::$url/archive/refs/tags/v$_pkgver.tar.gz)
sha512sums=('ce4fe1c7e1f41faa4468d98822ad302f7397d3c571a946c036065c393e8909b967761f7a6a61b97d1fe49968c6a1cbcc7e2b3adf0146d8c2966dc276c4d1801c')
b2sums=('0da371d18eb169ccc23e33f5242487d4f62c77467fd63e0a6c64f7615d4ada43aee7253c6b6cd01ec5b4f74a801af8da91c5ed5fe04705530e785b43d72d90f9')

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"
  # tests require UTC timezone: https://github.com/samuelcolvin/dirty-equals/issues/33
  TZ=UTC pytest "${pytest_options[@]}"
}

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