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

_realname=ffmpeg-python
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.2.0
pkgrel=1
pkgdesc='Python bindings for FFmpeg - with complex filtering support (mingw-w64)'
provides=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://github.com/kkroening/ffmpeg-python"
license=('Apache')
depends=("${MINGW_PACKAGE_PREFIX}-python-future" "${MINGW_PACKAGE_PREFIX}-ffmpeg")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest-mock")
makedepends=("unzip" "${MINGW_PACKAGE_PREFIX}-python-setuptools" "${MINGW_PACKAGE_PREFIX}-python-pytest-runner")
options=('!emptydirs')
source=("${_realname}-${pkgver}.zip::https://github.com/kkroening/ffmpeg-python/archive/${pkgver}.zip")
sha256sums=('0a6229ddcccff36dc199f877d2a06b00c2e2f7dee774233aae5e932c0ccdabf2')
noextract=("${_realname}-${pkgver}.zip") # bsdtar chokes on README symlink, we need unzip

prepare() {  
  cd "$srcdir"
  unzip "${_realname}-${pkgver}.zip"
  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
}

check() {
  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="$PWD/tmp_install" --optimize=1 --skip-build
  ${MINGW_PREFIX}/bin/pytest
}

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