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

_realname=xlsxwriter
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=1.4.3
pkgrel=1
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}=${pkgver}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgdesc="A Python module for creating Excel XLSL files (mingw-w64)"
url="https://github.com/jmcnamara/XlsxWriter"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest")
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/jmcnamara/XlsxWriter/archive/RELEASE_${pkgver}.tar.gz")
sha256sums=('88ca0d5a5446df800694479364da94cd90e861a2f5d5b8f2e0b8dac6cea9ae5d')

build() {
  cd "${srcdir}/XlsxWriter-RELEASE_${pkgver}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/XlsxWriter-RELEASE_${pkgver}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  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
}
