# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=docutils
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.21.2
pkgrel=1
pkgdesc="Set of tools for processing plaintext docs into formats such as HTML, XML, or LaTeX (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://docutils.sourceforge.io/"
msys2_changelog_url='https://docutils.sourceforge.io/HISTORY.html'
msys2_references=(
  'archlinux: python-docutils'
  'gentoo: dev-python/docutils'
  'purl: pkg:pypi/docutils'
)
license=('Public Domain' AND 'spdx:BSD-2-Clause AND ZPL-2.1 AND GPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-python-build"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
  "${MINGW_PACKAGE_PREFIX}-python-flit-core"
  "${MINGW_PACKAGE_PREFIX}-python-setuptools" # required for pyscript2exe.py
)
options=(!strip)
source=(https://pypi.io/packages/source/${_realname:0:1}/${_realname}/${_realname}-${pkgver}.tar.gz)
sha256sums=('3a6b18732edf182daa3cd12775bbb338cf5691468f91eeeb109deff6ebfa986f')
noextract=(${_realname}-${pkgver}.tar.gz)

prepare() {
  tar -xzf "${srcdir}"/${_realname}-${pkgver}.tar.gz -C "${srcdir}" || true

  rm -rf "python-build-${MSYSTEM}"
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"

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

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

  PYTHONUTF8=1 PYTHONPATH="$PWD/build/python/" ${MINGW_PREFIX}/bin/python test/alltests.py
}

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

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

  # setup license
  install -D -m644 COPYING.txt "${pkgdir}"${MINGW_PREFIX}/share/licenses/python-${_realname}/COPYING.txt
  install -D -m644 licenses/*.txt "${pkgdir}"${MINGW_PREFIX}/share/licenses/python-${_realname}/
}
