# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=tabulate
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.8.9
pkgrel=2
pkgdesc='Pretty-print tabular data in Python, a library and a command-line utility. (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://bitbucket.org/astanin/python-tabulate"
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-nose" "${MINGW_PACKAGE_PREFIX}-python-numpy" "${MINGW_PACKAGE_PREFIX}-python-pandas" "${MINGW_PACKAGE_PREFIX}-python-wcwidth")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-numpy: NumPy array support"
"${MINGW_PACKAGE_PREFIX}-python-pandas: pandas DataFrame support"
"${MINGW_PACKAGE_PREFIX}-python-wcwidth: wide-character support")
source=("https://files.pythonhosted.org/packages/source/${_realname:0:1}/${_realname//-/_}/${_realname//-/_}-${pkgver}.tar.gz")
sha256sums=('eb1d13f25760052e8931f2ef80aaf6045a6cceb47514db8beab24cded16f13a7')

prepare() {  
  cd "$srcdir"
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname//-/_}-$pkgver" "python-build-${CARCH}"
}

build() {
  msg "Python build for ${CARCH}"  
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py test || warning "Tests failed"
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  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
  
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    sed -e '1 { s/^#!.*$// }' -i ${_f}
  done
  
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
  install -vDm 644 README.md -t "${pkgdir}${MINGW_PREFIX}/share/doc/python-${_realname}/"
}
