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

_realname=tabulate
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.9.0
pkgrel=4
pkgdesc='Pretty-print tabular data in Python, a library and a command-line utility. (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'purl: pkg:pypi/tabulate'
)
url="https://github.com/astanin/python-tabulate"
license=('spdx:MIT')
options=(!strip)
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools-scm")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest"
              "${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://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('0095b12bf5966de529c0feb1fa08671671b3368eec77d7ef7ab114be2c068b3c')

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

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}/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 || warning "Tests failed"
}

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"
  install -vDm 644 README.md -t "${pkgdir}${MINGW_PREFIX}/share/doc/python-${_realname}/"
}
