# Maintainer:  Thore Bödecker <foxxx0@archlinux.org>
# Contributor: Laurent Soest <laurent.soest@gmail.com>
# Contributor: Angel Velasquez <angvp@archlinux.org>
# Contributor: Kaiting Chen <kaitocracy@gmail.com>
# Contributor: Douglas Soares de Andrade <dsa@aur.archlinux.org>
# Contributor: Armando M. Baratti <amblistas@ajato.com.br>
# Contributor: Florian Richter <Florian_Richter@gmx.de>

pkgname='python-cherrypy'
_pkgname="${pkgname#python-}"
pkgver=18.9.0
pkgrel=1
pkgdesc='A pythonic, object-oriented web development framework'
arch=('any')
url='https://cherrypy.dev'
license=('BSD-3-Clause')
depends=('python' 'python-cheroot' 'python-portend' 'python-jaraco.collections'
'python-more-itertools' 'python-zc.lockfile')
makedepends=('python-build' 'python-installer' 'python-setuptools' 'python-setuptools-scm' 'python-wheel')
checkdepends=('python-objgraph' 'python-path' 'python-pytest'
'python-pytest-forked' 'python-pytest-services' 'python-pytest-sugar'
'python-requests-toolbelt')
optdepends=(
  'python-flup: for xcgi support'
  'python-memcached: for memcached session support'
  'python-pyopenssl: for TLS support'
  'python-routes: for routes_dispatcher support'
  'python-simplejson: for JSON support'
)
source=(
  "${pkgname}-${pkgver}.tar.gz::https://github.com/${_pkgname}/${_pkgname}/archive/v$pkgver.tar.gz"
)
sha512sums=('a99ce1b1f86974bd7bee2b74571e4cd90448e5959c9cefe7db13443c78900ec3b99780286464656901773e29deba45f7817d41df6961a272dfa7b259b28c488d')

prepare() {
  cd ${_pkgname}-${pkgver}
  # apply patch from the source array (should be a pacman feature)
  local filename
  for filename in "${source[@]}"; do
    if [[ "$filename" =~ \.patch$ ]]; then
      echo "Applying patch ${filename##*/}"
      patch -p1 -N -i "$srcdir/${filename##*/}"
    fi
  done

  sed '/setuptools_scm_git_archive/d' -i pyproject.toml
}

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

  cd ${_pkgname}-${pkgver}
  python -m build --wheel --no-isolation
}

check() {
  local pytest_options=(
    -vv
    -o addopts=''  # we are not interested in coverage
    -o filterwarnings=''  # we don't want to fail on warnings
  )

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

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