# Maintainer: @naveen521kk on Github, Naveen M K <naveen521kk@gmail.com>

_realname=manim
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.18.1
pkgrel=3
pkgdesc="Animation engine for explanatory math videos (community edition) (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64')
url='https://www.manim.community'
msys2_repository_url='https://github.com/ManimCommunity/manim'
msys2_references=(
  'pypi: manim'
)
license=('spdx:MIT')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python"
  "${MINGW_PACKAGE_PREFIX}-ffmpeg"
  "${MINGW_PACKAGE_PREFIX}-python-click"
  "${MINGW_PACKAGE_PREFIX}-python-click-default-group"
  "${MINGW_PACKAGE_PREFIX}-python-numpy"
  "${MINGW_PACKAGE_PREFIX}-python-pillow"
  "${MINGW_PACKAGE_PREFIX}-python-scipy"
  "${MINGW_PACKAGE_PREFIX}-python-tqdm"
  "${MINGW_PACKAGE_PREFIX}-python-pydub"
  "${MINGW_PACKAGE_PREFIX}-python-rich"
  "${MINGW_PACKAGE_PREFIX}-python-cairo"
  "${MINGW_PACKAGE_PREFIX}-python-manimpango"
  "${MINGW_PACKAGE_PREFIX}-python-networkx"
  "${MINGW_PACKAGE_PREFIX}-python-decorator"
  "${MINGW_PACKAGE_PREFIX}-python-watchdog"
  "${MINGW_PACKAGE_PREFIX}-python-moderngl"
  "${MINGW_PACKAGE_PREFIX}-python-moderngl-window"
  "${MINGW_PACKAGE_PREFIX}-mapbox-earcut"
  "${MINGW_PACKAGE_PREFIX}-python-cloup"
  "${MINGW_PACKAGE_PREFIX}-python-requests"
  "${MINGW_PACKAGE_PREFIX}-python-skia-pathops"
  "${MINGW_PACKAGE_PREFIX}-python-isosurfaces"
  "${MINGW_PACKAGE_PREFIX}-python-srt"
  "${MINGW_PACKAGE_PREFIX}-python-screeninfo"
  "${MINGW_PACKAGE_PREFIX}-python-pygments"
  "${MINGW_PACKAGE_PREFIX}-python-svgelements"
  "${MINGW_PACKAGE_PREFIX}-python-typing_extensions"
)
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-poetry-core"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cc")
if [[ ${CARCH} != i686 ]]; then
  optdepends=("${MINGW_PACKAGE_PREFIX}-texlive-latex-extra: For LaTeX support")
fi
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('4bf2b479d258b410259c6828261fe79e107beb8f2dd04ebfa73b96bcefdde93d')

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

  sed -i 's/cloup = ">=0.13,<2.2"/cloup = "*"/g' pyproject.toml
  sed -i 's/isosurfaces = "0.1.0"/isosurfaces = "*"/g' pyproject.toml
  sed -i 's/Pillow = ">=9.1,<10.0"/Pillow = "*"/g' pyproject.toml
}

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

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

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