# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=labelme
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=5.2.1
pkgrel=5
pkgdesc='Image Polygonal Annotation with Python (polygon, rectangle, circle, line, point and image-level flag annotation). (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'aur: labelme'
  'pypi: labelme'
)
url="https://github.com/wkentaro/labelme"
license=('spdx:GPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-colorama"
         "${MINGW_PACKAGE_PREFIX}-python-imgviz"
         "${MINGW_PACKAGE_PREFIX}-python-matplotlib"
         "${MINGW_PACKAGE_PREFIX}-python-natsort"
         "${MINGW_PACKAGE_PREFIX}-python-numpy"
         "${MINGW_PACKAGE_PREFIX}-python-pillow"
         "${MINGW_PACKAGE_PREFIX}-python-pyqt5"
         "${MINGW_PACKAGE_PREFIX}-python-qtpy"
         "${MINGW_PACKAGE_PREFIX}-python-termcolor"
         "${MINGW_PACKAGE_PREFIX}-python-yaml")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
options=(!strip)
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('556c793b33b32de47324d60182c356ccefcbf8ae4a9217392b5f6a32ea5251e1')

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

build() {
  cd "${srcdir}/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 labelme/icons/icon.png "${pkgdir}${MINGW_PREFIX}/share/pixmaps/labelme.png"
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
