# Contributor: Marcelo Duarte https://github.com/marcelotduarte

_realname=pytest-subprocess
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=1.5.3
pkgrel=1
pkgdesc="Pytest plugin to fake subprocess (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'purl: pkg:pypi/pytest-subprocess'
)
url='https://github.com/aklajnert/pytest-subprocess'
license=('spdx:MIT')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python"
  "${MINGW_PACKAGE_PREFIX}-python-pytest"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-python-build"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
  "${MINGW_PACKAGE_PREFIX}-python-setuptools"
)
checkdepends=(
  "${MINGW_PACKAGE_PREFIX}-python-anyio"
  "${MINGW_PACKAGE_PREFIX}-python-docutils"
  "${MINGW_PACKAGE_PREFIX}-python-pytest"
  "${MINGW_PACKAGE_PREFIX}-python-pytest-asyncio"
  "${MINGW_PACKAGE_PREFIX}-python-pytest-rerunfailures"
  "${MINGW_PACKAGE_PREFIX}-python-pytest-timeout"
)
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname/-/_}-${pkgver}.tar.gz")
sha256sums=('c00b1140fb0211b3153e09500d770db10770baccbe6e05ee9c140036d1d811d5')

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

build() {
  cd "build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/pip install ${_realname} -f dist --no-deps --no-index
  ${MINGW_PREFIX}/bin/python -m pytest || warning "Tests failed"
  ${MINGW_PREFIX}/bin/pip uninstall -y ${_realname}
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

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

