# Contributor: Frederic Wang <fred.wang@free.fr>

_realname=pbr
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=6.1.1
pkgrel=1
pkgdesc="Python Build Reasonableness (mingw-w64)"
msys2_references=(
  'archlinux: python-pbr'
  'purl: pkg:pypi/pbr'
)
msys2_changelog_url='https://docs.openstack.org/pbr/latest/user/history.html'
msys2_documentation_url='https://docs.openstack.org/pbr/latest/'
msys2_issue_tracker_url='https://bugs.launchpad.net/pbr/'
msys2_repository_url='https://opendev.org/openstack/pbr/'
url='https://docs.openstack.org/pbr/latest/'
license=('spdx:Apache-2.0')
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-stestr"
              "${MINGW_PACKAGE_PREFIX}-python-testscenarios"
              "${MINGW_PACKAGE_PREFIX}-python-testresources"
              "${MINGW_PACKAGE_PREFIX}-python-testrepository"
              "${MINGW_PACKAGE_PREFIX}-python-mock"
              "${MINGW_PACKAGE_PREFIX}-python-virtualenv"
              "${MINGW_PACKAGE_PREFIX}-python-sphinx")
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        "0001-fix-for-new-setuptools.patch")
sha256sums=('93ea72ce6989eb2eed99d0f75721474f69ad88128afdef5ac377eb797c4bf76b'
            'c5bf2ba2d78e7dfde396620e1e9b7123dd84c4111a5578a308702a725fb384e5')

prepare() {
  cd "${srcdir}"
  sed -e 's/wheel.install/wheel.wheelfile/' \
      -e 's/wheel_file.zipfile/wheel_file/' \
      -i ${_realname}-$pkgver/pbr/tests/test_packaging.py

  cd "${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}"/0001-fix-for-new-setuptools.patch

  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() {
  msg "Python test for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    PYTHON=${MINGW_PREFIX}/bin/python ${MINGW_PREFIX}/bin/stestr run || 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 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
