# Maintainer: fauxpark <fauxpark@gmail.com>

_realname=milc
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=1.9.1
pkgrel=1
pkgdesc="Opinionated Batteries-Included Python 3 CLI Framework (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://milc.clueboard.co'
msys2_repository_url='https://github.com/clueboard/milc'
msys2_references=(
  'purl: pkg:pypi/milc'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-argcomplete"
         "${MINGW_PACKAGE_PREFIX}-python-colorama"
         "${MINGW_PACKAGE_PREFIX}-python-halo"
         "${MINGW_PACKAGE_PREFIX}-python-platformdirs"
         "${MINGW_PACKAGE_PREFIX}-python-spinners")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=(
  "https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
  "0001-temp-remove-types-colorama.patch")
sha256sums=('d89c9fa85984adca2e49b8f4a3a77bd649df6553c92583be38f55e9a9343a65e'
            'bd917622257c828f28dada2c241f40801961b761e3d06bcec2dedf9d7ddc0a9f')

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

  patch -p1 -i ../0001-temp-remove-types-colorama.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

  # Undo path translation
  sed -e '1 { s/^#!.*python.*$/#!\/usr\/bin\/env python3/ }' -i "${pkgdir}/${MINGW_PREFIX}/bin/milc-color"

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