# Maintainer: gym603 <gui_yuan_miao@163.com>

_pyname=Theano
_realname=theano
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.0.5
pkgrel=6
pkgdesc="Python library that allows you to define, optimize, and evaluate mathematical expressions involving multi-dimensional arrays efficiently (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64')
url="https://github.com/Theano/Theano"
msys2_references=(
  'pypi: Theano'
)
license=('spdx:BSD-3-Clause-Clear')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-numpy"
         "${MINGW_PACKAGE_PREFIX}-python-scipy"
         "${MINGW_PACKAGE_PREFIX}-python-six")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-wheel")
optdepends=("${MINGW_PACKAGE_PREFIX}-cc: Support to execute optimized C-implementations (for both CPU and GPU)")
options=(!strip)
source=(https://pypi.org/packages/source/${_pyname::1}/${_pyname}/${_pyname}-${pkgver}.tar.gz
        0001-cmodule-obtain-mingw-w64-python-library.patch
        0002-not-use-np.distutils.__config__.blas_opt_info.patch)
sha256sums=('6e9439dd53ba995fcae27bf20626074bfc2fff446899dc5c53cb28c1f9202e89'
            'fd4a66aac925abdd9316bb142784c97e63d42ef590dddddf5d1771e69ea189df'
            '532ed23eadd9623fb87c7c50e25f64d2b68fd24cb4b9f546be2a154685b5799a')

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -b -p1 -i "${srcdir}/${_patch}"
  done
}

prepare() {
  cd "${srcdir}"/${_pyname}-${pkgver}
  apply_patch_with_msg \
    0001-cmodule-obtain-mingw-w64-python-library.patch \
    0002-not-use-np.distutils.__config__.blas_opt_info.patch
}

build() {
  cp -r "${_pyname}-${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

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