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

_pyname=Pygments
_realname=pygments
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.19.1
pkgrel=1
pkgdesc="Python syntax highlighter (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'pypi: Pygments'
  "cpe: cpe:/a:pygments:pygments"
)
url="https://pygments.org/"
msys2_repository_url="https://github.com/pygments/pygments"
license=('spdx:BSD-2-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-hatchling"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-lxml"
              "${MINGW_PACKAGE_PREFIX}-python-pytest"
              "${MINGW_PACKAGE_PREFIX}-python-wcag-contrast-ratio")
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('61c16d2a8576dc0649d9f39e089b5f02bcd27fba10d8fb4dcc28173f7a45151f')

build () {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  PYTHONDONTWRITEBYTECODE=1 \
  ${MINGW_PREFIX}/bin/pytest
}

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 -Dm644 doc/pygmentize.1 -t "$pkgdir${MINGW_PREFIX}/share/man/man1"
}
