# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=jmespath
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.10.0
pkgrel=1
pkgdesc='A query language for JSON (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/jmespath/jmespath"
license=('Apache')
depends=("${MINGW_PACKAGE_PREFIX}-python")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-nose" "${MINGW_PACKAGE_PREFIX}-python-py")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=("https://github.com/jmespath/jmespath.py/archive/$pkgver.tar.gz")
sha256sums=('999b0ef13b798cf04de5451a51201d63a6feaf07c3fdcfbab4e5bca2b4ac653e')

prepare() {  
  cd "$srcdir"
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}.py-${pkgver}" "python-build-${CARCH}"
}

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

check() {
  cd "${srcdir}/python-build-${CARCH}"
  LC_CTYPE=en_US.utf8 ${MINGW_PREFIX}/bin/nosetests || warning "Tests failed"
}

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 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE.txt"

  local _PREFIX_WIN=$(cygpath -m ${MINGW_PREFIX})
  sed -s "s|${_PREFIX_WIN}/bin/||g" -i "${pkgdir}${MINGW_PREFIX}/bin/jp.py"
}
