# Maintainer: Maksim Bondarenkov <maksapple2306@gmail.com>

_pyname=sphinx_argparse
_realname=sphinx-argparse
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.5.2
pkgrel=1
pkgdesc="Sphinx extension that automatically documents argparse commands and options (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'pypi: sphinx-argparse'
)
url='https://github.com/sphinx-doc/sphinx-argparse'
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python-sphinx"
         "${MINGW_PACKAGE_PREFIX}-python-docutils")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-wheel"
             "${MINGW_PACKAGE_PREFIX}-python-flit-core")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest"
              "${MINGW_PACKAGE_PREFIX}-python-coverage"
              "${MINGW_PACKAGE_PREFIX}-python-lxml"
              "${MINGW_PACKAGE_PREFIX}-python-setuptools"
              "${MINGW_PACKAGE_PREFIX}-python-typing_extensions")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-commonmark: markdown support")
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_pyname}-${pkgver}.tar.gz")
sha256sums=('e5352f8fa894b6fb6fda0498ba28a9f8d435971ef4bbc1a6c9c6414e7644f032')

build() {
  cp -r "${_pyname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m pytest
}

package() {
  cd "python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENCE.rst "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENCE.rst"
}
