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

_realname=build
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=1.3.0
pkgrel=1
pkgdesc="A simple, correct Python build frontend (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'purl: pkg:pypi/build'
)
url='https://github.com/pypa/build'
license=('spdx:MIT')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python-packaging"
  "${MINGW_PACKAGE_PREFIX}-python-pyproject-hooks"
)
optdepends=(
  "${MINGW_PACKAGE_PREFIX}-python-colorama"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-python-flit-core"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
)
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        "0001-optional-colorama.patch")
sha256sums=('698edd0ea270bde950f53aed21f3a0135672206f3911e0176261a31e0e07b397'
            '2ad33a8d2d16bb09896dfe1020593bbe664e13d8ffd20cd7bc6f68d31d47e0e9')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -Np1 -i "${srcdir}/0001-optional-colorama.patch"
}

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  python -m flit_core.wheel
}

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

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

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