# Contributor: Noel Kuntze <noel.kuntze@thermi.consulting>
# Maintainer: Noel Kuntze <noel.kuntze@thermi.consulting>
pkgname=py3-sqlmodel
pkgver=0.0.22
pkgrel=1
pkgdesc="SQL databases in Python, designed for simplicity, compatibility, and robustness"
url="https://sqlmodel.tiangolo.com"
arch="noarch !loongarch64" # disabled due to py3-fastapi not being available on loongarch64
license="MIT"
depends="py3-pydantic py3-sqlalchemy pre-commit"
makedepends="
	py3-gpep517
	py3-wheel
	py3-pdm-backend"
checkdepends="
	py3-coverage
	py3-dirty-equals
	py3-fastapi
	py3-httpx
	py3-pytest
	"
subpackages="$pkgname-pyc"

source="$pkgname-$pkgver.tar.gz::https://github.com/fastapi/sqlmodel/archive/refs/tags/$pkgver.tar.gz"

builddir="$srcdir/sqlmodel-$pkgver"

build() {
	gpep517 build-wheel \
		--wheel-dir dist \
		--output-fd 3 3>&1 >&2
}

check() {
	local _site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
	python3 -m installer -d test_dir dist/*.whl
	export PYTHONPATH="$PWD/test_dir/$_site_packages:$PYTHONPATH"

	# Remove failing tests relying on old python versions
	rm -rf docs_src/tutorial/fastapi/app_testing/tutorial001_py39/test*.py \
		docs_src/tutorial/fastapi/app_testing/tutorial001_py310/test*.py \
		tests/test_tutorial/test_fastapi/test_app_testing/test*.py \
		tests/test_select_gen.py \
		tests/test_tutorial/test_create_db_and_table/test_tutorial001*.py \

	pytest -vv tests/
}

package() {
	python -m installer -d "$pkgdir" dist/*.whl
}

sha512sums="
f060617527a8c3551889a6a3acee63ffe7139de44d54da0820a6f78f8967b4ae5f23d94c9ccb82fe74619498a870c30e2b93467e7e8fbc2c458117534157e460  py3-sqlmodel-0.0.22.tar.gz
"
