# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=freetype-py
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.5.1
pkgrel=1
pkgdesc="Freetype python bindings (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/rougier/freetype-py'
msys2_references=(
  'purl: pkg:pypi/freetype-py'
)
license=('spdx:BSD-4-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-freetype")
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-certifi")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest")
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.zip"
        "0001-fix-loading-freetype-dll.patch")
sha256sums=('cfe2686a174d0dd3d71a9d8ee9bf6a2c23f5872385cf8ce9f24af83d076e2fbd'
            '41332a871f0edb1da6d5a8aba7c01fa4dd865f4327b51457fc5583bb2f27872c')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}"/0001-fix-loading-freetype-dll.patch

  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  export FREETYPEPY_BUNDLE_FT=
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m pytest
}

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"
}
