# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=mysqlclient
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.2.6
pkgrel=1
pkgdesc="Fork of MySQL-python with support for Python 3 (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64')
url='https://mysqlclient.readthedocs.io/'
msys2_repository_url='https://github.com/PyMySQL/mysqlclient-python'
msys2_references=(
  'pypi: mysqlclient'
)
license=('spdx:GPL-2.0-or-later')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python"
  "${MINGW_PACKAGE_PREFIX}-libmariadbclient"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-python-build"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
  "${MINGW_PACKAGE_PREFIX}-python-setuptools"
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-pkgconf"
)
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        0001-mysqlclient-setup-fix-linking.patch)
sha256sums=('c0b46d9b78b461dbb62482089ca8040fa916595b1b30f831ebbd1b0a82b43d53'
            '8faf97aca80aa48b49197c9a76862b5f73df8b6e3ce630eb641fc6bb2dc6ee9f')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/0001-mysqlclient-setup-fix-linking.patch"
}

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

  MYSQLCLIENT_CONNECTOR="${MINGW_PREFIX}" \
  ${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 "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
