# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=gcs-oauth2-boto-plugin
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=3.3
pkgrel=1
pkgdesc="Auth plugin allowing use the use of OAuth 2.0 credentials for Google Cloud Storage in the Boto library. (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://developers.google.com/storage/docs/gspythonlibrary'
msys2_repository_url='https://github.com/GoogleCloudPlatform/gcs-oauth2-boto-plugin'
msys2_references=(
  'purl: pkg:pypi/gcs-oauth2-boto-plugin'
)
license=('spdx:Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-rsa"
         "${MINGW_PACKAGE_PREFIX}-python-boto"
         "${MINGW_PACKAGE_PREFIX}-python-google-auth"
         "${MINGW_PACKAGE_PREFIX}-python-google-auth-httplib2"
         "${MINGW_PACKAGE_PREFIX}-python-google-reauth"
         "${MINGW_PACKAGE_PREFIX}-python-httplib2"
         "${MINGW_PACKAGE_PREFIX}-python-oauth2client"
         "${MINGW_PACKAGE_PREFIX}-python-pyopenssl"
         "${MINGW_PACKAGE_PREFIX}-python-retry-decorator"
         "${MINGW_PACKAGE_PREFIX}-python-six")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname//-/_}/${_realname//-/_}-${pkgver}.tar.gz"
        0001-setup.py-allow-newer-verions.patch)
sha256sums=('748e8f73161c884bc1251748b4920115201829ed9a258e7112e8bf8ce45eae18'
            '31d57c2e725440d318243af7828527918417008af790199a87ca5ce121d7cab3')

prepare() {
  cd "${srcdir}"/${_realname//-/_}-${pkgver}
  patch -p1 -i "${srcdir}"/0001-setup.py-allow-newer-verions.patch
}

build() {
  cp -r "${_realname//-/_}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  "${MINGW_PREFIX}"/bin/python -m pytest
}

package() {
  cd "${srcdir}"/python-build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

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