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

_realname=oslotest
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=5.0.1
pkgrel=1
pkgdesc="Oslo test framework (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/openstack/oslotest'
msys2_references=(
  'purl: pkg:pypi/oslotest'
)
license=('spdx:Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-fixtures"
         "${MINGW_PACKAGE_PREFIX}-python-subunit"
         "${MINGW_PACKAGE_PREFIX}-python-testtools")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-pbr"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=(
  "${MINGW_PACKAGE_PREFIX}-python-stestr"
)
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('5a9440d28d8ccb00bcf5fe7a05690417ea62943b0c8e93a4317d8b1bd02ee8ee')

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

  # Set version for pbr
  export PBR_VERSION=${pkgver}
}

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}"
  PYTHON=${MINGW_PREFIX}/bin/python ${MINGW_PREFIX}/bin/stestr run
}

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"

  local PREFIX_WIN=$(cygpath -wm ${MINGW_PREFIX})
  # fix python command in files
  sed -e "s|/usr/bin/env |${MINGW_PREFIX}|g" \
      -e "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" \
      -i "${pkgdir}${MINGW_PREFIX}/bin/oslo_run_pre_release_tests"
}
