# Contributor: Christoph Reiter <reiter.chrsitoph@gmail.com>
# Contributor: @naveen521kk on Github Naveen M K<naveen521kk@gmail.com>

_realname=matplotlib
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=3.10.7
pkgrel=1
pkgdesc="A python plotting library, making publication quality plots (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://matplotlib.org/'
msys2_repository_url="https://github.com/matplotlib/matplotlib"
msys2_references=(
  'archlinux: python-matplotlib'
  'gentoo: dev-python/matplotlib'
  'purl: pkg:pypi/matplotlib'
)
license=('custom')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-contourpy"
         "${MINGW_PACKAGE_PREFIX}-python-cycler"
         "${MINGW_PACKAGE_PREFIX}-python-fonttools"
         "${MINGW_PACKAGE_PREFIX}-python-kiwisolver"
         "${MINGW_PACKAGE_PREFIX}-python-numpy"
         "${MINGW_PACKAGE_PREFIX}-python-packaging"
         "${MINGW_PACKAGE_PREFIX}-python-pillow"
         "${MINGW_PACKAGE_PREFIX}-python-pyparsing"
         "${MINGW_PACKAGE_PREFIX}-python-dateutil"
         "${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-qhull")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools-scm"
             "${MINGW_PACKAGE_PREFIX}-meson-python"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pybind11"
             "${MINGW_PACKAGE_PREFIX}-cc")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-pyqt5: Qt5Agg/Qt5Cairo backend"
            "${MINGW_PACKAGE_PREFIX}-gtk3: GTK3Agg/GTK3Cairo backend"
            "${MINGW_PACKAGE_PREFIX}-python-gobject: GTK3Agg/GTK3Cairo backend"
            "${MINGW_PACKAGE_PREFIX}-python-cairo: cairo/GTK3Cairo/Qt5Cairo backend"
            "${MINGW_PACKAGE_PREFIX}-python-tornado: WebAgg backend")
source=("https://pypi.io/packages/source/${_realname:0:1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('a06ba7e2a2ef9131c79c49e63dad355d2d878413a0376c1727c8b9335ff731c7')

prepare() {
  cd "${srcdir}"
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

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

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation \
    -Csetup-args="-Dsystem-freetype=true" \
    -Csetup-args="-Dsystem-qhull=true"
}

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