# 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.53.1.0
pkgrel=1
pkgdesc="Python wrapper for SQLite"
arch=('x86_64' 'aarch64')
url="https://github.com/rogerbinns/apsw"
license=('MIT')
makedepends=('python-build' 'python-installer' 'python-wheel' 'python-setuptools' 'git')
depends=('python' 'sqlite')
source=("git+https://github.com/rogerbinns/apsw.git#tag=${pkgver}")
sha512sums=('f218ceb5415fc8630c41a3656bdc78d51287f2f47ea33171fcd5f841ef2df57934f6f6915bfd0d389f52db93212bf4fd86844b94f9d9e0b0bf2283fa1a6c10bb')
b2sums=('a6029e0475b092cac2cdbd2c0edd968c93016408ac33177afc06196361159c1be80c99c03200999881a60898eebb30315c738b4ae61cd8ceeb720a0d445d92cb')

build() {
  cd apsw

  python -m build --wheel --no-isolation
}

check() {
  cd apsw

  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])))')
  cd "build/lib.linux-$CARCH-cpython-${python_version}"
  python -m apsw.tests -v
}

package() {
  cd apsw

  python -m installer --destdir="$pkgdir" dist/*.whl
  install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
