# Contributor: Eli Schwartz <eschwartz@archlinux.org>
# Contributor: Brendan MacDonell <macdonellba at gmail dot com>
# Contributor: Linmiao Xu <linmiao.xu@gmail.com>
# Contributor: Juan Miguel Cejuela <juanmi@jmcejuela.net>

pkgname=python-apsw
pkgver=3.45.2.0
pkgrel=2
pkgdesc="Python wrapper for SQLite"
arch=('x86_64' 'aarch64')
url="https://github.com/rogerbinns/apsw"
license=('MIT')
makedepends=('python-setuptools')
depends=('python' 'sqlite')
source=("apsw-$pkgver.tar.gz::https://github.com/rogerbinns/apsw/archive/$pkgver.tar.gz")
sha512sums=('864cde25cfd15e3cbddbf1df80dbd861e93c2e8ea458a9f16d0ff4a8ecaf17721321f08bf7ab0659c0a18845be5bcc879b6708175ed971b263a0f274c08b05b9')
b2sums=('4071e2dc24a304f4f08cefc87cce27d617cab8f2699d134134b2c0c2618422139ebdd38dfafcb17e8a6c515fe5e799d6d827ef5099af23cf628f26c18764aa0a')

build() {
  cd apsw-${pkgver}

  python setup.py build --enable=load_extension
}

check() {
  cd "$srcdir"/apsw-${pkgver}

  gcc ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -fPIC -shared -o testextension.sqlext src/testextension.c
  # do glob expansion in variable assignment
  local python_version=$(python -c 'import sys; print("".join(map(str, sys.version_info[:2])))')
  PYTHONPATH="$PWD/build/lib.linux-$CARCH-cpython-${python_version}" python -m unittest discover -vs apsw
}

package() {
  cd "$srcdir"/apsw-${pkgver}

  python setup.py install --root="$pkgdir" --optimize=1 --skip-build
  install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
