# Maintainer: Ryuta Suzuki <oroppas@gmail.com>

_realname=xlsxwriter
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=3.2.9
pkgrel=1
pkgdesc="A Python module for creating Excel XLSL files (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: python-xlsxwriter'
  'gentoo: dev-python/xlsxwriter'
  'purl: pkg:pypi/xlsxwriter'
)
msys2_repository_url='https://github.com/jmcnamara/XlsxWriter'
url='https://xlsxwriter.readthedocs.io/'
msys2_changelog_url='https://xlsxwriter.readthedocs.io/changes.html'
license=('spdx:BSD-2-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python")
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=('254b1c37a368c444eac6e2f867405cc9e461b0ed97a3233b2ac1e574efb4140c')

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

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

  local _mingw_prefix=$(cygpath -am ${MINGW_PREFIX})
  for filename in vba_extract; do
    sed -e "s|${_mingw_prefix}/bin/|/usr/bin/env |g" -i "${pkgdir}${MINGW_PREFIX}"/bin/${filename}.py
  done
}
