# Maintainer: wszqkzqk <wszqkzqk@qq.com>

_realname=ocrmypdf
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=16.13.0
pkgrel=1
pkgdesc="A tool to add an OCR text layer to scanned PDF files, allowing them to be searched (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/ocrmypdf/OCRmyPDF"
msys2_documentation_url='https://ocrmypdf.readthedocs.io/'
msys2_changelog_url='https://ocrmypdf.readthedocs.io/en/latest/release_notes.html'
msys2_references=(
  'anitya: 15744'
  'aur: ocrmypdf'
  'purl: pkg:pypi/ocrmypdf'
)
license=('spdx:MPL-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-img2pdf"
         "${MINGW_PACKAGE_PREFIX}-ghostscript"
         "${MINGW_PACKAGE_PREFIX}-pngquant"
         "${MINGW_PACKAGE_PREFIX}-python-deprecation"
         "${MINGW_PACKAGE_PREFIX}-python-importlib_resources"
         "${MINGW_PACKAGE_PREFIX}-python-pdfminer"
         "${MINGW_PACKAGE_PREFIX}-python-pikepdf"
         "${MINGW_PACKAGE_PREFIX}-python-pillow"
         "${MINGW_PACKAGE_PREFIX}-python-pluggy"
         "${MINGW_PACKAGE_PREFIX}-python-reportlab"
         "${MINGW_PACKAGE_PREFIX}-python-rich"
         "${MINGW_PACKAGE_PREFIX}-python-tqdm"
         "${MINGW_PACKAGE_PREFIX}-python-packaging"
         "${MINGW_PACKAGE_PREFIX}-tesseract-ocr"
         "${MINGW_PACKAGE_PREFIX}-unpaper")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-hatchling"
             "${MINGW_PACKAGE_PREFIX}-python-hatch-vcs"
             "${MINGW_PACKAGE_PREFIX}-python-installer")
options=('!strip')
source=("https://files.pythonhosted.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('29d37e915234ce717374863a9cc5dd32d29e063dfe60c51380dda71254c88248')

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  sed -i '/^[[:space:]]*"pi-heif",/d' pyproject.toml
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

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

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