# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=mallard-ducktype
pkgbase=mingw-w64-python-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-python-${_realname}"
pkgver=1.0.2
pkgrel=7
pkgdesc="Parser for the lightweight Ducktype syntax for Mallard (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='http://projectmallard.org/'
msys2_references=(
  'archlinux: mallard-ducktype'
  'purl: pkg:pypi/mallard-ducktype'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python")
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")
sha256sums=('8e15319974460ed267729488b85ec00f7e97d89289721169483a2aacb144bdf7')

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}"
    ${MINGW_PREFIX}/bin/python -m pytest
}

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"

  local PREFIX_WIN=$(cygpath -wm ${MINGW_PREFIX})
  # fix python command in files
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*; do
    sed -e "s|/usr/bin/env |${MINGW_PREFIX}|g" \
        -e "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" -i ${_f}
  done
}
