# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Angel Velasquez <angvp@archlinux.org>
# Contributor: Sébastien Luttringer <seblu@aur.archlinux.org>

pkgname=python-sqlalchemy
_name="${pkgname#python-}"
pkgver=2.0.44
_ver="rel_${pkgver//./_}"
pkgrel=1
arch=('x86_64' 'aarch64')
url="https://www.sqlalchemy.org/"
license=('MIT')
pkgdesc='Python SQL toolkit and Object Relational Mapper'
depends=('glibc' 'python' 'python-greenlet' 'python-typing_extensions')  # HACK: typing_extensions is not required but upstream unconditionally imports it
optdepends=('python-psycopg: connect to PostgreSQL database'
            'python-psycopg2: connect to PostgreSQL database')
makedepends=('python-setuptools' 'python-build' 'python-installer' 'python-wheel' 'cython')
checkdepends=('python-pytest' 'python-pytest-xdist' 'mypy')
source=("$pkgname-$pkgver.tar.gz::https://github.com/sqlalchemy/sqlalchemy/archive/refs/tags/${_ver}.tar.gz")
# https://github.com/sqlalchemy/sqlalchemy/discussions/11138
#validpgpkeys=('83AF7ACE251C13E6BB7DEFBD330239C1C4DAFEE1')
sha512sums=('cdc48908b72b5d418c7edfe4ec775dd9fde2e7c161084daf1870a17ba9039bb67ff9c71506aa8acf76bab35b758efdd91de254b535db323252da61415a8825c9')

prepare() {
  cd $_name-$_ver
  sed -i '/warnings.filterwarnings("error", category=DeprecationWarning)/a \    warnings.filterwarnings("ignore", category=DeprecationWarning, message="Creating a LegacyVersion has been deprecated and will be removed in the next major release")' \
      lib/sqlalchemy/testing/warnings.py

  # strip dev for https://gitlab.archlinux.org/archlinux/packaging/packages/python-sqlalchemy/-/issues/1
  sed -i '/tag-build = "dev"/d' pyproject.toml
  sed -i '/tag_build = dev/d' setup.cfg
}

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

check() {
  cd $_name-$_ver
  PYTHONPATH=build/lib pytest
}

package() {
  cd $_name-$_ver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -D -m644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
}

# vim:set ts=2 sw=2 ft=sh et:
