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

_realname=google-auth-oauthlib
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.4.4
pkgrel=1
pkgdesc='oauthlib integration for Google auth. (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="http://google-auth-oauthlib.readthedocs.io/en/latest/"
license=('Apache')
depends=("${MINGW_PACKAGE_PREFIX}-python-google-auth" "${MINGW_PACKAGE_PREFIX}-python-requests-oauthlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-click" "${MINGW_PACKAGE_PREFIX}-python-pytest" "${MINGW_PACKAGE_PREFIX}-python-mock")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-click")
options=('!emptydirs')
source=("https://pypi.org/packages/source/${_realname:0:1}/$_realname/$_realname-$pkgver.tar.gz")
sha256sums=('09832c6e75032f93818edf1affe4746121d640c625a5bef9b5c96af676e98eee')

prepare() {  
  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
}

check() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/pytest || 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 "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"

  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    sed -e '1 { s/^#!.*$// }' -i ${_f}
  done
}
