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

_realname=labelme
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=4.5.7
pkgrel=2
pkgdesc='Image Polygonal Annotation with Python (polygon, rectangle, circle, line, point and image-level flag annotation). (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://github.com/wkentaro/labelme"
license=('GPL')
depends=("${MINGW_PACKAGE_PREFIX}-python-imgviz" "${MINGW_PACKAGE_PREFIX}-python-termcolor" "${MINGW_PACKAGE_PREFIX}-python-qtpy")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-pyqt5: Qt backend")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=("$_realname-${pkgver}.tar.gz::https://github.com/wkentaro/labelme/archive/v${pkgver}.tar.gz")
sha256sums=('86600f49854a9f6e7debb5e39d9a21679174668c060de1c4637f8dd0a8713f21')

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

build() {
  msg "Python build for ${CARCH}"  
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    sed -e '1 { s/^#!.*$// }' -i ${_f}
  done

  install -Dm644 labelme/icons/icon.png "${pkgdir}${MINGW_PREFIX}/share/pixmaps/labelme.png"
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
