# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Timothée Ravier <tim@siosm.fr>

pkgname=python-dulwich
_name=${pkgname#python-}
pkgver=0.25.2
pkgrel=1
pkgdesc='Pure-Python implementation of the Git file formats and protocols'
arch=(x86_64 aarch64)
url=https://www.dulwich.io
license=('Apache-2.0 OR GPL-2.0-or-later')
depends=(
  python
  python-urllib3
)
makedepends=(
  git
  python-build
  python-installer
  python-setuptools-rust
  python-wheel
)
checkdepends=(
  openssh
  python-fastimport
  python-gevent
  python-gpgme
  python-merge3
  python-paramiko
  python-pytest
)
optdepends=(
  'python-fastimport: for fast-import support'
  'python-gpgme: for PGP signature support'
  'python-idna: for HTTPS support via urllib3'
  'python-merge3: for merge support'
  'python-paramiko: for use as the SSH implementation'
  'python-pyopenssl: for HTTPS support via urllib3'
  'python-pyinotify: to watch for changes to refs'
  'python-rich: for colorized diff support'
)
source=("git+https://github.com/jelmer/dulwich.git#tag=dulwich-$pkgver")
b2sums=('710183318307877089f412f4cdc58a4640c7baa5ad51edda94e1066c77f5dce148904abbab5fb6b8c34b1affdb863906cde9afcdcb1b95ad596104bbedf45196')
validpgpkeys=(DC837EE14A7E37347E87061700806F2BD729A457) # Jelmer Vernooĳ <jelmer@jelmer.uk>

prepare() {
  cd "$_name"
  cargo fetch --locked --target "$(rustc --print host-tuple)"
}

build() {
  cd "$_name"
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  local pytest_options=(
    -v
    --ignore tests/contrib/test_swift_smoke.py
    --deselect tests/test_porcelain.py::AddTests::test_add_symlink_absolute_to_system
  )

  cd "$_name"
  cargo test --frozen --all-features
  pytest "${pytest_options[@]}" tests
}

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