# 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=25.5.0
pkgrel=1
pkgdesc="Structured Logging for Python"
url="https://www.structlog.org"
# https://github.com/hynek/structlog/blob/24.2.0/pyproject.toml#L14
license=('MIT OR Apache-2.0')
arch=('any')
depends=('python')
# openssh needed to verify SSH signatures
makedepends=('git' 'openssh' 'python-build' 'python-installer'
             'python-hatchling' 'python-hatch-vcs' 'python-hatch-fancy-pypi-readme')
checkdepends=('python-pytest' 'python-freezegun' 'python-simplejson'
              'python-twisted' 'python-rapidjson' 'python-greenlet' 'python-pytest-asyncio'
              'python-rich' 'python-better-exceptions' 'python-time-machine')
optdepends=(
  'python-greenlet: for greenlet support in structlog.threadlocal (deprecated)'
  'python-twisted: for structlog.twisted'
  'python-rich: for structlog.dev'
  'python-better-exceptions: for structlog.dev'
)
# The PyPI tarball is signed, but missing conftest.py
source=("git+https://github.com/hynek/structlog.git#tag=$pkgver"
        "ssh_allowed_signers")
sha512sums=('68754d386172270f0c6de76f02dab971e710fcb1cfac0368732871efa3da714d519048c616b56a5148487e8c585451ebed176d208cba7082f31c8d658f8b3710'
            '6ccc3793e6128783b745879785264f66961a6d3aeefd4c39746503490fe0c36c92807f3149ed601fdaaf84be244a6b24882a337025a2dd317a96d75b50f1fabd')

# XXX: move to verify() when devtools supports it
# https://gitlab.archlinux.org/archlinux/devtools/-/issues/224
prepare() {
  git -C structlog -c gpg.ssh.allowedSignersFile="$srcdir/ssh_allowed_signers" verify-tag $pkgver
}

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
  install -Dm644 LICENSE-{APACHE,MIT} -t "$pkgdir"/usr/share/licenses/$pkgname
}
