# Maintainer: gym603 <gui_yuan_miao@163.com>

_pyname=Keras
_realname=keras
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=2.3.1
pkgrel=4
pkgdesc="Keras is a high-level neural networks API, written in Python and capable of running on top of TensorFlow, CNTK, or Theano (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://keras.io/"
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-numpy"
         "${MINGW_PACKAGE_PREFIX}-python-scipy"
         "${MINGW_PACKAGE_PREFIX}-python-six"
         "${MINGW_PACKAGE_PREFIX}-python-yaml"
         "${MINGW_PACKAGE_PREFIX}-python-h5py"
         "${MINGW_PACKAGE_PREFIX}-python-keras_applications"
         "${MINGW_PACKAGE_PREFIX}-python-keras_preprocessing"
         "${MINGW_PACKAGE_PREFIX}-python-theano")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=(https://pypi.org/packages/source/${_realname::1}/${_realname}/${_pyname}-${pkgver}.tar.gz
        0001-change-backend-to-theano.patch)
sha256sums=('321d43772006a25a1d58eea17401ef2a34d388b588c9f7646c34796151ebc8cc'
            '2e53d3c474d0d797ef7c6faf3ecdc77dfe123fa43bd19a151caaf894baadb47e')


# 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-change-backend-to-theano.patch

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

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py --quiet build
}

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

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python setup.py --quiet install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1 --skip-build

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