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

_realname=pythran
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.18.0
pkgrel=2
pkgdesc="Ahead of Time compiler for numeric kernels (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/serge-sans-paille/pythran"
msys2_documentation_url="https://pythran.readthedocs.io/"
msys2_references=(
  'purl: pkg:pypi/pythran'
)
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-xsimd"
         "${MINGW_PACKAGE_PREFIX}-python-beniget"
         "${MINGW_PACKAGE_PREFIX}-python-gast"
         "${MINGW_PACKAGE_PREFIX}-python-ply"
         "${MINGW_PACKAGE_PREFIX}-python-numpy")
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.python.org/packages/source/${_realname:0:1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        001-fix-default-config.patch)
sha256sums=('5c003e8cbedf6dbb68c2869c49fc110ce8b5e8982993078a4a819f1dadc4fc6a'
            'aa03979a1ede62e1ea19d17eeaa3208afa4ddfa89bc0f70435dca41be7f8730f')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/001-fix-default-config.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

  rm -r "$pkgdir"${MINGW_PREFIX}/lib/python*/site-packages/pythran/{boost,xsimd} # Remove bundled boost and xsimd

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