# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Simon Sapin <simon dot sapin at exyr dot org>
# Contributor: Kyle Keen <keenerd@gmail.com>

pkgname=python-factory-boy
pkgver=3.3.0
pkgrel=5
pkgdesc="A versatile test fixtures replacement based on thoughtbot's factory_bot for Ruby"
url="https://github.com/FactoryBoy/factory_boy"
license=('MIT')
arch=(any)
depends=('python-faker')
makedepends=('python-build' 'python-installer' 'python-setuptools' 'python-wheel')
checkdepends=('python-pytest' 'python-flask' 'python-django' 'python-sqlalchemy'
              'python-sqlalchemy-utils' 'python-flask-sqlalchemy' 'python-mongoengine'
              'python-mongomock')
source=("$pkgname-$pkgver.tar.gz::https://github.com/FactoryBoy/factory_boy/archive/$pkgver.tar.gz"
        https://github.com/FactoryBoy/factory_boy/commit/f0859075b048b85c8ed44c051f18070cbd20d03d.patch
	use-mongomock.patch)
sha512sums=('483e7454dbbafdf6ba2ec8924ccd648585c5ad5676da0af222a942beb3ebdbf4c372bb963c948d8a87a5359c1277b45b226239ff6109e11dbc1851ef5fd7275f'
            'c9fd3ecc6598547a39ec588d634f8ace46090f02518732420e8dcb14f373983c02ed91c1e7ec28777007ebd66f4179ed4a407a4252c8402e861b75748c3d813f'
            'd3e96582ef2cb12900b56cc0f25386f7bed3e6910d3417a48f66de9ae2de9a9c5b1a4fb31c69bbde481cdd47bbe421825e93804f6513068ba53af7cba9517c84')

prepare() {
  cd factory_boy-$pkgver
  # Fix test_version
  patch -p1 -i ../f0859075b048b85c8ed44c051f18070cbd20d03d.patch

  patch -Np1 -i ${srcdir}/use-mongomock.patch
}

build() {
  cd factory_boy-$pkgver
  python -m build -nw
}

check() {
  cd factory_boy-$pkgver
  python -m installer -d tmp_install dist/*.whl
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  PYTHONPATH=tmp_install/"${site_packages}" pytest
}

package() {
  cd factory_boy-$pkgver
  python -m installer -d "$pkgdir" dist/*.whl
  install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
}
