# Maintainer: Patrick Stewart <patstew@gmail.com>

_realname=pyzmq
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=26.4.0
pkgrel=2
pkgdesc="Python bindings for zeromq, written in Cython (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.zeromq.org/languages/python"
msys2_repository_url="https://github.com/zeromq/pyzmq"
msys2_documentation_url='https://pyzmq.readthedocs.io'
msys2_references=(
  'purl: pkg:pypi/pyzmq'
)
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-zeromq")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-scikit-build-core"
             "${MINGW_PACKAGE_PREFIX}-python-packaging"
             "${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        "002-mingw-win-compat.patch")
sha256sums=('4bd13f85f80962f91a651a7356fe0472791a5f7a92f227822b5acf44795c626d'
            'c2e01fbdb3fc7c9eda0b5be128027536c6338b349eb1550da6067b3bde2acd3b')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}"/002-mingw-win-compat.patch
}

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "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

  local PREFIX_WIN=$(cygpath -wm ${MINGW_PREFIX})
  # fix absolute paths in config files
  find "${pkgdir}${MINGW_PREFIX}" -name "*.json" -exec sed -e "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" -i {} \;
}
