# Maintainer: Sarah Ottinger

_realname=pytest-mock
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=3.6.1
pkgrel=1
pkgdesc='Thin-wrapper around the mock package for easier use with py.test (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/pytest-dev/pytest-mock/"
license=('LGPL3')
depends=("${MINGW_PACKAGE_PREFIX}-python-pytest")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools-scm")
source=("${_realname}-$pkgver.tar.gz::https://github.com/pytest-dev/pytest-mock/archive/v$pkgver.tar.gz")
sha256sums=('f4cbdd4315a44a40cb824cde8291c3d43eb046d2cc4113c5c330dc9805f11440')

export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver

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
}

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 || warning "Tests failed"
  PYTHONPATH="$PWD/tmp_install/${MINGW_PREFIX}/lib/python3.8/site-packages:$PYTHONPATH:$PWD/tests" ${MINGW_PREFIX}/bin/py.test || warning "Tests failed"
}

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/python-${_realname}/LICENSE"
}
