# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=rst2pdf
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-rst2pdf")
pkgver=0.103.1
pkgrel=2
pkgdesc="Create PDFs from simple text markup, no LaTeX required (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://rst2pdf.org"
msys2_repository_url="https://github.com/rst2pdf/rst2pdf"
msys2_references=(
  'purl: pkg:pypi/rst2pdf'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-docutils"
         "${MINGW_PACKAGE_PREFIX}-python-importlib-metadata"
         "${MINGW_PACKAGE_PREFIX}-python-jinja"
         "${MINGW_PACKAGE_PREFIX}-python-packaging"
         "${MINGW_PACKAGE_PREFIX}-python-pygments"
         "${MINGW_PACKAGE_PREFIX}-python-reportlab"
         "${MINGW_PACKAGE_PREFIX}-python-smartypants"
         "${MINGW_PACKAGE_PREFIX}-python-yaml")
# TODO: package python-xhtml2pdf
# https://github.com/xhtml2pdf/xhtml2pdf/issues/560
optdepends=("${MINGW_PACKAGE_PREFIX}-python-pyphen: for hyphenation support"
            "${MINGW_PACKAGE_PREFIX}-python-matplotlib: for math support'"
            "${MINGW_PACKAGE_PREFIX}-python-sphinx: for sphinx support"
            "${MINGW_PACKAGE_PREFIX}-python-svglib: for SVG support")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools-scm")
options=(!strip)
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('3ffe816d4b3275aee21b8ffdd08b2e6be4d7590cd88b189f733cbc6996d63786')

prepare() {
  cd "${_realname}-${pkgver}"
  sed -i 's/"packaging~=24\.0"/"packaging~=25.0"/' pyproject.toml
  cd -

  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${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 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE.txt"
}
