# Maintainer: @naveen521kk on Github, Naveen M K <naveen521kk@gmail.com>

_pyname=setuptools-git
_realname=setuptools-git
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=1.2
pkgrel=6
pkgdesc="Setuptools revision control system plugin for Git (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/msabramo/setuptools-git"
msys2_references=(
  'archlinux: python-setuptools-git'
  'purl: pkg:pypi/setuptools-git'
)
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python"
        'git')
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=(
  "https://pypi.org/packages/source/${_pyname::1}/${_pyname}/${_pyname}-${pkgver}.tar.gz"
  "0001-use-git-show-prefix.patch"
)
sha256sums=('ff64136da01aabba76ae88b050e7197918d8b2139ccbf6144e14d472b9c40445'
            '8b3874cff964543de07eca3c22fa01d009fa8769abe8a6035278371fe1ee35e2')

prepare() {
  cd "${_pyname//_/-}-$pkgver"
  patch -p1 -i "${srcdir}"/0001-use-git-show-prefix.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
}

check(){
  cd "${srcdir}/python-build-${MSYSTEM}/${pyname}"
  ${MINGW_PREFIX}/bin/python -m unittest || true
}

package() {
  cd "${srcdir}"/python-build-${MSYSTEM}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl
}
