# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=python-sphinxcontrib-towncrier
pkgver=0.5.0a0
pkgrel=1
pkgdesc='A RST directive for injecting a Towncrier-generated changelog draft containing fragments for the unreleased (next) project version'
arch=(any)
url='https://github.com/sphinx-contrib/sphinxcontrib-towncrier'
license=(BSD-3-Clause)
depends=(
  python
  python-sphinx
  towncrier
)
makedepends=(
  git
  python-build
  python-installer
  python-setuptools
  python-setuptools-scm
  python-wheel
)
checkdepends=(python-pytest python-pytest-xdist)
source=("$pkgname::git+$url#tag=v$pkgver")
sha512sums=('3fad2bd259155fd2c2051ca12bf1c84322bb2186063b544e9e784b3162061971af573a726d25f88db82b95f3a1434f44b54698a28406217dbba3dddc27216d6c')
b2sums=('2cd0596a51e12281b8750f5eacff6d86d8d70383efa3c372d63d0c17dd144ce5bf6ac3186ab7897bffe7485d22160e1175a3b56db2beb76b8f9f63a4ca30a341')

prepare() {
  cd "$pkgname"

  # skip coverage tests
  sed -i '/pytest_cov/d;/--cov/d' pytest.ini

  # Do not treat warnings as errors
  sed -i '/^  error$/d' pytest.ini
}

build() {
  cd "$pkgname"

  SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver python -m build --wheel --no-isolation
}

check() {
  cd "$pkgname"

  PYTHONPATH="$PWD/src" pytest -v
}

package() {
  cd "$pkgname"

  python -m installer --destdir="$pkgdir" dist/*.whl

  # license
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE
}
