# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: Eli Schwartz <eschwartz@archlinux.org>

pkgname=python-genshi
pkgver=0.7.10
pkgrel=3
pkgdesc='Toolkit for stream-based generation of output for the web'
arch=(x86_64 aarch64)
url='https://genshi.edgewall.org'
license=(BSD-3-Clause)
depends=(
  glibc
  python
)
makedepends=(
  git
  python-build
  python-installer
  python-setuptools
  python-wheel
)
checkdepends=(python-pytest)
source=("$pkgname::git+https://github.com/edgewall/genshi#tag=$pkgver")
sha512sums=('816872a2c59ed40540b3845289f7c49708439a4bfb89d8bbaed7e582da5a2c4c6966fb57c271bc97a56bab0669112066a4d333fc989401600f44ad30eaf98d49')
b2sums=('7d37269f9e3a8c722692a5bb7ceaed850df61b2292136db8028a1dbaf6dfbb9b6750daeaa59375461be4122229445dbf553c1c6c5e9a17de97470c9d50ad231f')

prepare() {
  cd "$pkgname"
  # Port from pkg_resources to importlib.resources (#97)
  git cherry-pick -n a31979dcc8d1b974ddff36301472b348664414a3
}

build() {
  cd "$pkgname"

  python -m build --wheel --no-isolation
}

check() {
  cd "$pkgname"

  # install to temporary directory
  python -m installer --destdir="$PWD/tmp_install" dist/*.whl
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  export PYTHONPATH="$PWD/tmp_install$site_packages"

  # skip doctests
  pytest -v --import-mode=importlib -c /dev/null
}

package() {
  cd "$pkgname"

  python -m installer --destdir="$pkgdir" dist/*.whl

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" COPYING
}
