# Maintainer: David Runge <dvzrv@archlinux.org>

_name=binaryornot
pkgname=python-binaryornot
pkgver=0.4.4
pkgrel=12
pkgdesc="Ultra-lightweight pure Python package to check if a file is binary or text"
arch=(any)
url="https://github.com/binaryornot/binaryornot"
license=(BSD-3-Clause)
depends=(
  python
  python-chardet
)
makedepends=(
  python-build
  python-installer
  python-setuptools
  python-wheel
)
checkdepends=(python-hypothesis)
source=(
  $_name-$pkgver.tar.gz::$url/archive/refs/tags/$pkgver.tar.gz
  $pkgname-0.4.4-hypothesis_tests.patch::$url/pull/52.patch
  $pkgname-0.4.4-set_version.patch::$url/commit/cff1a0a4478c17d4f970d133c06abbf6945b6a5e.patch
)
sha512sums=('58825a0554e7012025386f4330ada1d8389999d1ef2e957a2dbd25b6722b3c84342285c936aa429fa476d6945b1276a97661a46b4fdd13de78ed7591fa1544ef'
            '8a0f1066a580f08778434ed7d30c2ebf2764dbfd746b561ffce2fb8dd8d77cafaf4a58b03504cf5b1e4d37e0a6ffe3038dcaa5611cdfd7d42ada86edd1e47f3f'
            'a56266b54b5000e4cdaadcca2119f1822ab1de1b45adee1095ab8841dc0289cc853b4e3e2be1079786f18dde84424a78909f33130f3081d3fa5cf352026ce1c0')
b2sums=('c14beb2f32fac8a450666a60d2dad82637ee0f519accb03f28a37d0bcca809635480afe2bac89d87f5042078fdba47f5391c2c1044d103e1ac980e5b51910c9b'
        'f07730709f11bf0732b60b81603c40bea1fa6da2d8df545b088072e0f710a7e123e438b03d2390122b6000c14343e932b38d4b6f8956ea87b72e29deae1a4715'
        'd56fb5a064be3ce810f274bb2e49e9afd921b536b9194da07a87fedd7e403af0edf0e4e05e975efa55b3d7deefd2ad71a2b36a1f1da45c653344f64478b1a613')

prepare() {
  # fix tests using python-hypothesis: https://github.com/audreyr/binaryornot/issues/46
  patch -Np1 -d $_name-$pkgver -i ../$pkgname-0.4.4-hypothesis_tests.patch
  # fix version as the wrong commit was tagged: https://github.com/binaryornot/binaryornot/issues/210
  # patch -Np1 -d $_name-$pkgver -i ../$pkgname-0.4.4-set_version.patch
}

build() {
  cd $_name-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  cd $_name-$pkgver
  python -m unittest discover -vs tests
}

package() {
  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -vDm 644 {AUTHORS,CONTRIBUTING,HISTORY,README}.rst -t "$pkgdir/usr/share/doc/$pkgname/"
}
