# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Maintainer: Daniel M. Capella <polyzen@archlinux.org>

pkgname=python-pyhamcrest
pkgver=2.1.0
pkgrel=3
pkgdesc="Hamcrest framework for matcher objects"
arch=('any')
license=('BSD-2-Clause')
url="https://github.com/hamcrest/PyHamcrest"
depends=('python')
makedepends=(
  'git'
  'openssh'
  'python-build'
  'python-installer'
  'python-hatchling'
  'python-hatch-vcs'
)
checkdepends=('python-pytest')
source=(
  "git+https://github.com/hamcrest/PyHamcrest.git#tag=V$pkgver"
  'ssh_allowed_signers'
)
b2sums=('8a6c3251cb5e3803668b0068bf2143171f8e56594ec287d584dd1ecc0c941d95a742ed7891f18d593ed75e053d05f9bc3aa0f098f28ee05deffabbdcd302fb6d'
        '972dd9382ae1fea4e41114bdc42d0691fff4d5002857acbd56e1a2b2bd7a1797a7b4366f15a92a1aaae042159a13d4cb55ad0dacf3bdc19cad306eb2f789d340')

# XXX: move to verify() when devtools supports it
# https://gitlab.archlinux.org/archlinux/devtools/-/issues/224
prepare() {
  git -C PyHamcrest -c gpg.ssh.allowedSignersFile="$srcdir/ssh_allowed_signers" verify-commit V$pkgver
}

build() {
  cd PyHamcrest
  python -m build -nw
}

check() {
  cd PyHamcrest
  PYTHONPATH="$PWD/src" pytest
}

package() {
  cd PyHamcrest
  python -m installer -d "$pkgdir" dist/*.whl

  # Symlink license file
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir"/usr/share/licenses/$pkgname
  ln -s "$site_packages"/${pkgname#python-}-$pkgver.dist-info/licenses/LICENSE.txt \
    "$pkgdir"/usr/share/licenses/$pkgname/LICENSE.txt
}
