# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=contourpy
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=1.3.3
pkgrel=1
pkgdesc="Python library for calculating contours of 2D quadrilateral grids (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://contourpy.readthedocs.io/'
msys2_repository_url='https://github.com/contourpy/contourpy/'
msys2_references=(
  'archlinux: python-contourpy'
  'purl: pkg:pypi/contourpy'
)
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-numpy")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-pybind11"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-meson-python"
             "${MINGW_PACKAGE_PREFIX}-pkgconf")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        "0001-dont-force-msvc.patch")
sha256sums=('083e12155b210502d0bca491432bb04d56dc3432f95a979b429f2848c3dbe880'
            'db3ea827fc9a3b4d50d863929d7d443502db8b25a0f167678330bbefb7c55952')

prepare() {
  cd "${_realname}-${pkgver}"

  patch -Np1 -i "${srcdir}/0001-dont-force-msvc.patch"
}

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 "python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m pytest || warning "Tests failed"
}

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 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
