# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Ionut Biru <ibiru@archlinux.org>
# Contributor: Juergen Hoetzel <juergen@archlinux.org>
# Contributor: Douglas Soares de Andrade <douglas@archlinux.org>

pkgname=python-twisted
pkgver=24.7.0
pkgrel=1
pkgdesc="Asynchronous networking framework written in Python"
arch=('any')
url="https://twistedmatrix.com/"
license=('MIT')
depends=(
  'python'
  'python-attrs'
  'python-automat'
  'python-constantly'
  'python-hyperlink'
  'python-incremental'
  'python-typing_extensions'
  'python-zope-interface'
)
makedepends=(
  'python-build'
  'python-hatch-fancy-pypi-readme'
  'python-hatchling'
  'python-installer'
  'python-wheel'
)
optdepends=(
  'python-appdirs: for using conch'
  'python-bcrypt: for using conch'
  'python-cryptography: for using conch'
  'python-h2: for http2 support'
  'python-idna: for TLS client hostname verification'
  'python-priority: for http2 support'
  'python-pyasn1: for using conch'
  'python-gobject: for GObject Introspection support'
  'python-pyopenssl: for TLS client hostname verification'
  'python-pyserial: for serial support'
  'python-service-identity: for TLS client hostname verification'
  'tk: for using tkconch'
)
checkdepends=(
  'cairo'
  'git'
  'glib2'
  'gtk3'
  'libffi'
  'libgirepository'
  'openssh'
  'python-bcrypt'
  'python-cryptography'
  'python-cython-test-exception-raiser'
  'python-gobject'
  'python-h2'
  'python-hypothesis'
  'python-idna'
  'python-priority'
  'python-pyasn1'
  'python-pyhamcrest'
  'python-pyopenssl'
  'python-pyserial'
  'python-service-identity'
  'python-subunit'
  'subversion'
  'tk'
  'xorg-server-xvfb'
)
source=("https://github.com/twisted/twisted/archive/twisted-$pkgver.tar.gz")
sha512sums=('7c919f956bced94b39b9f196910ad8022e94b4ed199a7a5a5c7edd6600bb13ed7bd9bca4af46338ae593b9da8a1559bd9658e51bcffa33a37b6a5125b89477b1')

build() {
  cd twisted-twisted-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  export LC_CTYPE=en_US.UTF-8

  # tests use the underlying function from the 'python -m twisted.trial' module, to prevent loading system entry points
  PYTHONPATH="$srcdir/twisted-twisted-$pkgver/src" xvfb-run python -c 'from twisted.scripts.trial import run; run()' twisted || echo "Tests failed"
}

package() {
  cd twisted-twisted-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
}
