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

_realname=setuptools-scm-git-archive
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=1.4.1
pkgrel=2
pkgdesc='setuptools_scm plugin for git archives (mingw-w64)'
url='https://github.com/Changaco/setuptools_scm_git_archive'
license=('spdx:MIT')
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'purl: pkg:pypi/setuptools-scm-git-archive'
)
depends=("${MINGW_PACKAGE_PREFIX}-python-setuptools-scm")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-python-build"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
  "${MINGW_PACKAGE_PREFIX}-python-setuptools"
)
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname//-/_}-${pkgver}.tar.gz")
sha256sums=('c418bc77b3974d3ac65f268f058f23e01dc5f991f2233128b0e16a69de227b09')

build() {
  cp -r "${_realname//-/_}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  "${MINGW_PREFIX}"/bin/python -v tests.py || warning "Tests failed"
}

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

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

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
