# Maintainer: wszqkzqk <wszqkzqk@qq.com>

_realname=pdfminer
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=20251107
pkgrel=1
pkgdesc="Python PDF Parser (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/pdfminer/pdfminer.six"
license=('spdx:MIT')
msys2_references=(
  'archlinux: python-pdfminer'
  'purl: pkg:pypi/pdfminer.six'
)
depends=("${MINGW_PACKAGE_PREFIX}-python-charset-normalizer"
         "${MINGW_PACKAGE_PREFIX}-python-cryptography")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools-scm"
             "${MINGW_PACKAGE_PREFIX}-python-wheel"
             "${MINGW_PACKAGE_PREFIX}-cython")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest")
source=("${url}/archive/${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('1a0eaa1447008bf4f33be37e3703ae3c51109613c5b0aa5117711354c06abc4a')

build() {
  cp -r "${_realname}.six-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver} \
    python -m build --wheel --no-isolation
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  PYTHONPATH="${PWD}"/build/lib:"${PWD}" \
    python -m pytest -vv --color=yes
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    python -m installer --prefix=${MINGW_PREFIX} \
      --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
