# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Maintainer: Chih-Hsuan Yen <yan12125@archlinux.org>

pkgname=python-structlog
# https://github.com/hynek/structlog/blob/main/CHANGELOG.md
pkgver=24.1.0
# curl https://api.github.com/repos/hynek/structlog/git/ref/tags/$pkgver | jq -r .object.sha
_tag=3dac758cc28fc063067cfce57e37c67b16daf00d
pkgrel=1
pkgdesc="Structured Logging for Python"
url="https://www.structlog.org"
license=('Apache')
arch=('any')
depends=('python')
makedepends=('git' 'python-build' 'python-installer'
             'python-hatchling' 'python-hatch-vcs' 'python-hatch-fancy-pypi-readme')
checkdepends=('python-pytest' 'python-freezegun' 'python-pretend' 'python-simplejson'
              'python-twisted' 'python-rapidjson' 'python-greenlet' 'python-pytest-asyncio'
              'python-rich')
optdepends=(
  'python-greenlet: for greenlet support in structlog.threadlocal (deprecated)'
  'python-twisted: for structlog.twisted'
  'python-rich: for structlog.dev'
)
# The PyPI tarball is signed, but missing conftest.py
source=("git+https://github.com/hynek/structlog.git?signed#tag=$_tag")
sha512sums=('SKIP')
validpgpkeys=(
  'C2A04F86ACE28ADCF817DBB7AE2536227F69F181'  # https://keys.openpgp.org/vks/v1/by-fingerprint/C2A04F86ACE28ADCF817DBB7AE2536227F69F181
)

pkgver() {
  cd structlog
  git describe --tags
}

build() {
  cd structlog
  python -m build --wheel --no-isolation
}

check() {
  cd structlog
  # Install to a temporary root for test_packaging
  pyver=$(python -c "import sys; print('{}.{}'.format(*sys.version_info[:2]))")
  python -m installer --destdir="$PWD/tmp_install" dist/*.whl
  PYTHONPATH="$PWD/tmp_install/usr/lib/python$pyver/site-packages" pytest tests
}

package() {
  cd structlog
  python -m installer --destdir="$pkgdir" dist/*.whl
}
