# Maintainer: wszqkzqk <wszqkzqk@qq.com>

_realname=python-pikepdf
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=9.9.0
pkgrel=1
pkgdesc='Read and write PDFs with Python, powered by qpdf'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/pikepdf/pikepdf'
msys2_references=(
  "anitya: 17724"
  "archlinux: $_realname"
  "cpe: cpe:2.3:a:pikepdf_project:pikepdf"
  "gentoo: dev-python/pikepdf"
  "purl: pkg:pypi/pikepdf"
)
license=('spdx:MPL-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-deprecated"
         "${MINGW_PACKAGE_PREFIX}-python-lxml"
         "${MINGW_PACKAGE_PREFIX}-python-packaging"
         "${MINGW_PACKAGE_PREFIX}-python-pillow"
         "${MINGW_PACKAGE_PREFIX}-qpdf")
makedepends=(git
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-pybind11"
             "${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-hypothesis"
              "${MINGW_PACKAGE_PREFIX}-python-psutil"
              "${MINGW_PACKAGE_PREFIX}-python-pytest-xdist")
source=("${url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('cda2f80b5309cd096cca77c7545e55d139f60d345c15817ef17538376e0dd983')

prepare() {
  rm -rf python-build-${MSYSTEM} | true
  cp -r pikepdf-${pkgver} "python-build-${MSYSTEM}"
}

build() {
  cd "python-build-${MSYSTEM}"
  python -m build --wheel --no-isolation --skip-dependency-check
}

check() {
  cd "python-build-${MSYSTEM}"
  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  test-env/bin/python -m pytest -v
}

package() {
  cd "python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    python -m installer --prefix=${MINGW_PREFIX} \
      --destdir="$pkgdir" dist/*.whl
  install -Dm644 LICENSE.txt -t "${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname"
}
