# Maintainer: Peter Budai <peterbudai@hotmail.com>

_realname=scikit-learn
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=0.22.2.post1
pkgrel=1
pkgdesc="A set of python modules for machine learning and data mining (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='http://scikit-learn.sourceforge.net/'
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-scipy"
         "${MINGW_PACKAGE_PREFIX}-python-joblib")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cython")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/scikit-learn/${_realname}/archive/${pkgver}.tar.gz"
        001-mingw-python-openmp-flag.patch
        002-openmp-cleanup-wait.patch)
sha256sums=('c6c57326941b1854112e6730961f31995ea60fa254e79daae1994e4cd5cb6f44'
            '11c9fedec28d882c25c90087ec3ef09f022dfd83c308574d023c89d19b5520f0'
            '6d4c0d35d09f87da3993634e1a1e9f89a14179fb75b1ee28e1a2a714bc70346f')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-mingw-python-openmp-flag.patch
  patch -p1 -i ${srcdir}/002-openmp-cleanup-wait.patch

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

build() {
  msg "Python build for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

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

  install -d ${pkgdir}${MINGW_PREFIX}/share/doc/python-${_realname}
  cp -r doc/tutorial ${pkgdir}${MINGW_PREFIX}/share/doc/python-${_realname}/tutorial
}
