# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Sherlock Holo <sherlockya@gmail.com>
# Contributor: user6553591 <Message on Reddit>

pkgname=python-websockets
pkgver=12.0
pkgrel=2
pkgdesc='Python implementation of the WebSocket Protocol (RFC 6455)'
url='https://github.com/aaugustin/websockets'
arch=('x86_64' 'aarch64')
license=('BSD')
depends=('python')
makedepends=(
  'python-build'
  'python-installer'
  'python-setuptools'
  'python-sphinx'
  'python-sphinx-copybutton'
  'python-sphinx-furo'
  'python-sphinx-inline-tabs'
  'python-sphinxcontrib-spelling'
  'python-sphinxcontrib-trio'
  'python-sphinxext-opengraph'
  'python-wheel'
)
source=(https://github.com/aaugustin/websockets/archive/${pkgver}/${pkgname}-${pkgver}.tar.gz)
sha512sums=('f17943d444ce275b709cf89453b2d2cce09f5af26f0460e226c2e24cfbb425c825963352e130dcd4201587606355375b525d8e5a02eccbffbb3985a108a3ed5e')
b2sums=('cab704e0ee44a7012ee58d515a5ea7380a97a3cbb8f55d105c00c8c2b9ed992b4c87435875474de32e5969fd92256bdec830db0571399a1d2e5fb719b23c2d83')

build() {
  cd websockets-${pkgver}
  python -m build --wheel --skip-dependency-check --no-isolation
  sphinx-build -b dirhtml docs docs/_build/html
  sphinx-build -b man docs docs/_build/man
}

check() {
  cd websockets-${pkgver}
  PYTHONPATH="$PWD/src" python -m unittest discover -v
}

package() {
  cd websockets-${pkgver}
  python -m installer --destdir="${pkgdir}" dist/*.whl
  install -Dm 644 README.rst -t "${pkgdir}/usr/share/doc/${pkgname}"
  cp -rT docs/_build/html "${pkgdir}/usr/share/doc/${pkgname}"
  install -Dm 644 docs/_build/man/websockets.1 "${pkgdir}/usr/share/man/man1/${pkgname}.1"

  # Symlink license file
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "${pkgdir}/usr/share/licenses/${pkgname}"
  ln -s "${site_packages}/websockets-${pkgver}.dist-info/LICENSE" \
    "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

# vim: ts=2 sw=2 et:
