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

_name=pytest-examples
pkgname=python-pytest-examples
pkgver=0.0.18
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=('2fa893ca977418df252a4c3d705054dbecc84b3cbcc90135aa29d6a3c77adfceb1452ad8fc43cf3def69ad2f5e333f678ae83acf2635c8e335ad812a5f852cc0')
b2sums=('6a4c4c436e8bf7148debd7cce5869710ba34f209fb152e4222a2ccddffd9d816ff14f5282dfd1f2b7bafe374cb294da75e563f8a285ceeccca702e71815e6db9')

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