# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: David Runge <dvzrv@archlinux.org>

_name=pytest-examples
pkgname=python-pytest-examples
pkgver=0.0.13
pkgrel=1
pkgdesc="Pytest plugin for testing examples in docstrings and markdown files"
arch=(any)
url="https://github.com/pydantic/pytest-examples"
license=(MIT)
depends=(
  python
  python-black
  python-pytest
  python-ruff
)
makedepends=(
  python-build
  python-hatchling
  python-installer
)
source=($_name-$pkgver.tar.gz::$url/archive/refs/tags/v$pkgver.tar.gz)
sha512sums=('32226c7a91ee5e00ff1e65bd5739e87d59be6f7c67ac3537fde974711314d51fef08e078d77fd3e24d239414537c2e8c246a672a7bf056e1efbb618dd64b2e74')
b2sums=('aae5143a34a640d683afae4278863323134b27035d979a843efa966ed1ef5ee5f91321afd613a3ac1b75fcd2dbc179c0dcc200cba7267bba9a2270f5de415d36')

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 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -vDm 644 README.md -t "$pkgdir/usr/share/doc/$pkgname/"
}
