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

_realname=subunit
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=1.4.5
pkgrel=1
pkgdesc="Python implementation of subunit test streaming protocol (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://launchpad.net/subunit'
msys2_repository_url='https://github.com/testing-cabal/subunit'
msys2_changelog_url='https://github.com/testing-cabal/subunit/blob/master/NEWS'
msys2_references=(
  'archlinux: python-subunit'
  'purl: pkg:pypi/python-subunit'
)
license=('spdx:Apache-2.0 OR BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-iso8601"
         "${MINGW_PACKAGE_PREFIX}-python-testtools")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-fixtures"
              "${MINGW_PACKAGE_PREFIX}-python-hypothesis"
              "${MINGW_PACKAGE_PREFIX}-python-testscenarios")
options=('!strip')
source=("https://pypi.io/packages/source/p/python-subunit/python_subunit-${pkgver}.tar.gz")
sha512sums=('7d87cc7538023a507de31ac1ca6be3fc7d1a2bd7865c246299593e00b57eff35c77016754050bbe35cc5a0717a552f95814e281a8f5d4dc09b7917433786b5a6')

build() {
  cp -r "python_${_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}"
  PYTHONPATH="$PWD/build/lib" python -m testtools.run subunit.test_suite || warning "Tests failed"
}

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