# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Thore Bödecker <foxxx0@archlinux.org>
# Contributor: wangjiezhe <wangjiezhe AT yandex DOT com>

_name=cheroot
pkgname=python-cheroot
pkgdesc="Highly-optimized, pure-python HTTP server"
pkgver=10.0.0
pkgrel=2
arch=(any)
url="https://github.com/cherrypy/cheroot"
license=(BSD-3-Clause)
depends=(
  python
  python-jaraco.functools
  python-more-itertools
)
optdepends=(
  'python-pyopenssl: for SSL and certificate handling within cheroot'
)
makedepends=(
  python-build
  python-installer
  python-setuptools
  python-setuptools-scm
  python-wheel
)
# TODO: package python-pypytools
checkdepends=(
  python-apipkg
  python-chardet
  python-colorama
  python-jaraco.context
  python-portend
  python-pyopenssl
  python-pytest
  python-pytest-forked
  python-pytest-mock
  python-pytest-rerunfailures
  python-pytest-sugar
  python-pytest-xdist
  python-requests-toolbelt
  python-requests-unixsocket
  python-trustme
  python-urllib3
  python-watchdog
)
source=($pkgname-$pkgver.tar.gz::$url/archive/refs/tags/v$pkgver.tar.gz)
sha512sums=('bfeebded828607441d91e4d6c2704df90387aa516744b59642d7daf5dc7e3b5f960066d9437aee61800e269046f14d72ee0c6078c1a84ec32c58323d3ad08156')
b2sums=('cc3bf89af3b59ec16f9cf276baf565f5c3637f42c70a01f35d70c0541fdc809dfeccd2c0d7cd3de576162442b3013b869b2fca09195dc9734fae7e6a2affdf9b')

prepare() {
  cd $_name-$pkgver
  # remove the use of python-setuptools-scm-git-archive
  # TODO: change upstream (and bump their setuptools-scm use to >= 7.0.5)
  sed -e '/setuptools_scm_git_archive/d' -i pyproject.toml setup.cfg requirements/*
}

build() {
  # setuptools wont find version from git tag
  export SETUPTOOLS_SCM_PRETEND_VERSION="$pkgver"

  cd $_name-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  local pytest_options=(
    -vv
    -o addopts=''
    --ignore cheroot/test/test_server.py  # requires python-pypytools
    # issues with python-pyopenssl (being too new?!)
    --deselect cheroot/test/test_ssl.py::test_https_over_http_error
  )

  cd $_name-$pkgver
  pytest "${pytest_options[@]}"
}

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

# vim:set ts=2 sw=2 et:
