# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgbase=python-pytest-cache
pkgname=('python-pytest-cache' 'python2-pytest-cache')
_name=pytest-cache
pkgver=1.0
pkgrel=8
pkgdesc='pytest plugin with mechanisms for caching across test runs'
arch=('any')
license=('MIT')
url='https://pypi.org/project/pytest-cache/'
makedepends=('python-setuptools' 'python-pytest' 'python2-pytest' 'python-execnet' 'python2-execnet')
source=(https://files.pythonhosted.org/packages/source/${_name::1}/$_name/$_name-$pkgver.tar.gz)
sha256sums=('be7468edd4d3d83f1e844959fd6e3fd28e77a481440a7118d430130ea31b07a9')

prepare() {
  cp -a "${srcdir}/${_name}-${pkgver}"{,-py2}
}

build() {
  cd "$srcdir/$_name-$pkgver"
  python setup.py build

  cd "$srcdir/$_name-$pkgver-py2"
  python2 setup.py build
}

check() {(
  # Hack entry points by installing it

  cd "$srcdir/$_name-$pkgver"
  python setup.py install --root="$PWD/tmp_install" --optimize=1
  PYTHONPATH="$PWD/tmp_install/usr/lib/python3.9/site-packages:$PYTHONPATH" py.test

  cd "$srcdir/$_name-$pkgver-py2"
  python2 setup.py install --root="$PWD/tmp_install" --optimize=1
  PYTHONPATH="$PWD/tmp_install/usr/lib/python2.7/site-packages:$PYTHONPATH" py.test2
  ) || echo "Tests failed"
  # Skipping tests as it's incompatibility with pytest 2.8.0, not python 3.5.
  # https://bitbucket.org/hpk42/pytest-cache/issues/11/tests-failed-with-pytest-280
}

package_python-pytest-cache() {
  depends=('python-pytest' 'python-execnet')

  cd "$srcdir/$_name-$pkgver"
  python setup.py install --root="$pkgdir"/ --optimize=1
  install -D -m644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

package_python2-pytest-cache() {
  depends=('python2-pytest' 'python2-execnet')

  cd "$srcdir/$_name-$pkgver-py2"
  python2 setup.py install --root="$pkgdir"/ --optimize=1
  install -D -m644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
# vim:set ts=2 sw=2 et:
