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

_realname=backports.functools_lru_cache
pkgbase=mingw-w64-python2-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-python2-${_realname}"
pkgver=1.5
pkgrel=1
pkgdesc="Backport of functools.lru_cache from Python 3.3 as published at ActiveState (mingw-w64)"
arch=('any')
url='https://github.com/jaraco/backports.functools_lru_cache'
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python2-backports")
makedepends=("${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python2-pytest-runner")
optdepends=("${MINGW_PACKAGE_PREFIX}-python2-ipaddress: for IPAddress ServerAltnames support")
options=('staticlibs' 'strip' '!debug')
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/jaraco/backports.functools_lru_cache/archive/$pkgver.tar.gz")
sha256sums=('735e2d2985f0200637feffdf0bba8ef46f7feee1fd166f2d6a30df935416e5e9')

# 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 python2-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python2-build-${CARCH}"
  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver
}

# Note that build() is sometimes skipped because it's done in 
# the packages setup.py install for simplicity if you can do so.
# but sometimes, you want to do a check before install which would
# also trigger the build.
build() {
    msg "Python 2 build for ${CARCH}"  
    cd python2-build-${CARCH}
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
}

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

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
  # This looks odd but the backports namespace module was imported earlier
  rm "$pkgdir${MINGW_PREFIX}/lib/python2.7/site-packages/backports/"__init__.py*
}

