# Maintainer: Ross Demuth <rossdemuth123@gmail.com>

_realname=pyodbc
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=5.2.0
pkgrel=2
pkgdesc="ODBC module for Python"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/mkleehammer/pyodbc'
license=('spdx:MIT-0')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cc")
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        "0001-build-fix.patch")
sha256sums=('de8be39809c8ddeeee26a4b876a6463529cd487a60d1393eb2a93e9bcd44a8f5'
            '98f2fbee77a8d02946f5af1d8217ad7fcf93c1e6e26eb26424e9d27de201eabd')

prepare() {
  cd "${_realname}-${pkgver}"

  patch -Np1 -i "${srcdir}/0001-build-fix.patch"
}

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

  python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

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