# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=singledispatch
pkgbase=mingw-w64-python-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-python2-${_realname}"
pkgver=3.4.0.3
pkgrel=1
pkgdesc="Implementation of functools.singledispatch from Python 3.4 (mingw-w64)"
arch=('any')
url='https://pypi.org/project/singledispatch/'
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python2"
         "${MINGW_PACKAGE_PREFIX}-python2-six")
makedepends=("${MINGW_PACKAGE_PREFIX}-python3-setuptools")
options=('staticlibs' 'strip' '!debug')
source=("https://pypi.python.org/packages/source/s/singledispatch/singledispatch-$pkgver.tar.gz" 
         license)
sha256sums=('5b06af87df13818d14f08a028e42f566640aef80805c3b50c5056b086e3c2b9c'
            '9f12db4a042a57e2c17e478a30c2b335ed88ceaa99e95a65542df475006510dc')

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

del_file_exists() {
  for _fname in "$@"
  do
    if [ -f $_fname ]; then
      rm -rf $_fname
    fi
  done
}
# =========================================== #

prepare() {
  cd "${srcdir}"
  rm -rf ${builddir} | true
  cp -r "${_realname}-${pkgver}" "python2-build-${CARCH}"
  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver
}

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

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

package() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2")

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

  install -Dm644 ${srcdir}/license "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/license"
}
