# Maintainer: Jeremy Drake <github@jdrake.com>

_realname=os-win
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=5.9.0
pkgrel=3
pkgdesc="Windows/Hyper-V Python library for OpenStack projects (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'purl: pkg:pypi/os-win'
)
url='https://opendev.org/openstack/os-win'
license=('spdx:Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-python-pbr"
         "${MINGW_PACKAGE_PREFIX}-python-eventlet"
         "${MINGW_PACKAGE_PREFIX}-python-oslo-concurrency"
         "${MINGW_PACKAGE_PREFIX}-python-oslo-config"
         "${MINGW_PACKAGE_PREFIX}-python-oslo-log"
         "${MINGW_PACKAGE_PREFIX}-python-oslo-utils"
         "${MINGW_PACKAGE_PREFIX}-python-oslo-i18n"
         "${MINGW_PACKAGE_PREFIX}-python-pymi"
         "${MINGW_PACKAGE_PREFIX}-python-wmi")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-hacking"
              "${MINGW_PACKAGE_PREFIX}-python-coverage"
              "${MINGW_PACKAGE_PREFIX}-python-ddt"
              "${MINGW_PACKAGE_PREFIX}-python-oslotest"
              "${MINGW_PACKAGE_PREFIX}-python-stestr"
              "${MINGW_PACKAGE_PREFIX}-python-testscenarios"
              "${MINGW_PACKAGE_PREFIX}-python-testtools")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        'iscsidsc-optional.patch')
sha256sums=('4d4ad5122060cdd1312d6909921c7280c7159fa6811a966fa11688fc141808c0'
            'd42fbecedc662000097f500ea41a16f55bba114382aa9ffd6dca2da1e08189c7')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  # there is no arm64 iscsidsc.dll
  patch -Nbp1 -i "${srcdir}/iscsidsc-optional.patch"
}

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}"
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  msg "Python test for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/stestr run -t ./os_win/tests
}

package() {
  msg "Python install for ${MSYSTEM}"
  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"
}
