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

_realname=ffmpeg-python
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.2.0
pkgrel=7
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=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/kkroening/ffmpeg-python"
msys2_references=(
  'aur: python-ffmpeg'
  'purl: pkg:pypi/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-build"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
)
options=('!emptydirs')
source=("${_realname}-${pkgver}.zip::https://github.com/kkroening/ffmpeg-python/archive/${pkgver}.zip"
        "0001-remove-unused-pytest-runner-dep.patch")
sha256sums=('0a6229ddcccff36dc199f877d2a06b00c2e2f7dee774233aae5e932c0ccdabf2'
            '31b5cc3d17cf35f3ebc760cd0fbc95594580ffa36b5e93b21fdd2ef99fb49b45')
noextract=("${_realname}-${pkgver}.zip") # bsdtar chokes on README symlink, we need unzip

prepare() {
  cd "$srcdir"
  unzip "${_realname}-${pkgver}.zip"
  cd "${_realname}-${pkgver}"
  patch -Np1 -i ../0001-remove-unused-pytest-runner-dep.patch

  cd "$srcdir"
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  cd "python-build-${MSYSTEM}"

  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "python-build-${MSYSTEM}"
  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 "python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
