# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Maintainer: Robin Candau <antiz@archlinux.org>
# Contributor: Kyle Keen <keenerd@gmail.com>
# Contributor: minder

pkgname=python-pillow
pkgver=12.2.0
pkgrel=1
pkgdesc='Python Imaging Library (PIL) fork'
arch=(x86_64 aarch64)
url='https://pillow.readthedocs.io'
license=(MIT-CMU)
depends=(
  glibc
  python
  python-packaging
  freetype2
  lcms2
  libavif
  libraqm
  libtiff
  openjpeg2
  libjpeg-turbo
  libimagequant
  libxcb
  zlib
)
makedepends=(
  git
  pybind11
  python-build
  python-installer
  python-wheel
  python-setuptools
  libwebp
  tk
)
checkdepends=(
  python-pytest
  python-pytest-timeout
)
optdepends=(
  'libwebp: for webp images'
  'tk: for the ImageTK module'
  'python-olefile: OLE2 file support'
  'python-pyqt6: for the ImageQt module'
  'python-defusedxml: for reading XMP tags'
)
source=(
  "$pkgname::git+https://github.com/python-pillow/Pillow#tag=$pkgver"
)
sha512sums=('6aa33974d04826e9ae7fa458e32eb11b6e87b6a1f29aad9542d698a0f08ebf1c4111d5a75189bc93e2959fb24fa525ee672289f928644eaddba76e43cba2f1f5')
b2sums=('8205207450bf0e5a50e82411bdbd4827e0706893ea2999092e689731ed8506bbb1007e9c76508fceb520582eda3a65080fbc5f5f046ca8575c3f8d78d46f4639')

prepare() {
  cd "$pkgname"
  git cherry-pick -n 24696af8898f86007252c5774da9f14f2be93879
}


build() {
  cd "$pkgname"

  python -m build --wheel --no-isolation
}

check() {
  cd "$pkgname"

  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  test-env/bin/python selftest.py
  test-env/bin/python -m pytest -v
}

package() {
  cd "$pkgname"

  python -m installer --destdir="$pkgdir" dist/*.whl

  local python_version=$(python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
  install -vDm644 -t "$pkgdir/usr/include/python$python_version" src/libImaging/*.h

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE
}
