# Contributor: Runar Tenfjord < runar dot tenfjord at gmail dot com >

_realname=numexpr
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-$_realname")
pkgver=2.13.0
pkgrel=1
pkgdesc="Fast numerical array expression evaluator for Python, NumPy, PyTables, pandas (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/pydata/numexpr"
msys2_changelog_url='https://github.com/pydata/numexpr/blob/master/RELEASE_NOTES.rst'
msys2_references=(
  'archlinux: python-numexpr'
  'gentoo: dev-python/numexpr'
  'purl: pkg:pypi/numexpr'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-numpy"
         "${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        "001-fix-building-on-mingw.patch")
sha256sums=('3363d804f202437586447a49b5c83b01322e8be72279d49e0bf524720edc01b6'
            'cb2df265e38b79cfc386695c9e74a128662ba5901939d400c591d45cc1cabe63')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/001-fix-building-on-mingw.patch

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

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