# Contributor: dragon-archer <dragon-archer@outlook.com

_realname=pytest-mpl
_pkgname=pytest_mpl
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.19.0
pkgrel=1
pkgdesc='A pytest plugin to facilitate image comparison for Matplotlib figures (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/matplotlib/pytest-mpl'
msys2_repository_url='https://github.com/matplotlib/pytest-mpl'
msys2_references=(
  'purl: pkg:pypi/pytest-mpl'
)
license=('spdx:BSD-2-Clause AND BSD-3-Clause')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python"
  "${MINGW_PACKAGE_PREFIX}-python-pytest"
  "${MINGW_PACKAGE_PREFIX}-python-matplotlib"
  "${MINGW_PACKAGE_PREFIX}-python-packaging"
  "${MINGW_PACKAGE_PREFIX}-python-jinja"
  "${MINGW_PACKAGE_PREFIX}-python-pillow"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-python-setuptools"
  "${MINGW_PACKAGE_PREFIX}-python-setuptools-scm"
  "${MINGW_PACKAGE_PREFIX}-python-build"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
)
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_pkgname}-${pkgver}.tar.gz")
sha256sums=('c08e7b51ba4c98eed77ac3f3c6e336ed6163647d9e27ea1d928f79b542178cbe')

build() {
  cp -r "${_pkgname}-${pkgver}" "python-build-${MSYSTEM}"
  cd "python-build-${MSYSTEM}"
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "python-build-${MSYSTEM}"
  PYTHONPATH=. ${MINGW_PREFIX}/bin/pytest || warning "Tests failed!"
}

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

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

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
