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

_realname=versioneer
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.29
pkgrel=4
pkgdesc="Easy VCS-based management of project version strings (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/python-versioneer/python-versioneer'
msys2_references=(
  'purl: pkg:pypi/versioneer'
)
license=('spdx:Unlicense')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        "001-fix-build.patch"
        "002-allow-override.patch")
sha256sums=('5ab283b9857211d61b53318b7c792cf68e798e765ee17c27ade9f6c924235731'
            '04c0afd639faba3fa1d03528be738013e5e19796502ed42ee599dbf748da3d18'
            '29745390b59afa994de7759bb9877ab9395ce30f7031cb68202c1e6f822f1fe8')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/001-fix-build.patch

  # https://github.com/python-versioneer/python-versioneer/issues/230
  patch -p1 -i "${srcdir}"/002-allow-override.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
}

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"
}
