# Contributor: James White <stegoxorus@gmail.com>
# Maintainer: James White <stegoxorus@gmail.com>
pkgname=py3-h5py
pkgver=3.12.1
pkgrel=0
pkgdesc="Read and write HDF5 files from Python"
url="https://www.h5py.org"
# 32-bit: tests fail due to size mismatch between python and cython, broken
arch="all !x86 !armhf !armv7"
license="BSD-3-Clause"
depends="py3-numpy"
makedepends="
	cython
	hdf5-dev
	liblzf-dev
	py3-gpep517
	py3-numpy-dev
	py3-pkgconfig
	py3-setuptools
	py3-wheel
	python3-dev
	"
checkdepends="
	py3-pytest
	py3-pytest-mpi
	py3-pytest-xdist
	"
subpackages="$pkgname-pyc"
source="$pkgname-$pkgver.tar.gz::https://github.com/h5py/h5py/archive/refs/tags/$pkgver.tar.gz
	"
case "$CARCH" in
ppc64le) options="!check" ;; # failing
esac
builddir="$srcdir/h5py-$pkgver"

replaces="py-h5py" # Backwards compatibility
provides="py-h5py=$pkgver-r$pkgrel" # Backwards compatibility

prepare() {
	default_prepare
	sed -i "s/settings\\['runtime_library_dirs'\\] = settings\\['library_dirs'\\]/pass/" setup_build.py

}

build() {
	export H5PY_SYSTEM_LZF=1
	# Stop requiring a specific version of numpy
	export H5PY_SETUP_REQUIRES=0
	export CFLAGS="$CFLAGS -Wno-incompatible-pointer-types"
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	rm -rf testenv
	python3 -m venv --clear --without-pip --system-site-packages .testenv
	.testenv/bin/python3 -m installer .dist/*.whl
	cd .testenv
	bin/python3 -m pytest -n ${JOBS:-2} --pyargs h5py -k "not test_too_small_pbs and not test_reopen and not test_multiprocess"
}

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

	rm -r "$pkgdir"/usr/lib/python3*/site-packages/h5py/tests
}

sha512sums="
d741b377605b2aef2847731ddb8bc9fc06eece0882ccc32b0f74e52a50ca217a9813298df77c6ae4a9eca3ed1148f58314746308d341fb58200a25dab3cbd5e2  py3-h5py-3.12.1.tar.gz
"
