# Maintainer: Luke T. Shumaker <lukeshu@parabola.nu>
#
# Rationale for inclusion in [pcr]: lukeshu uses this

pkgname='mailprocessing'
pkgver=1.2.7.r16.g71630de
# Go past 1.2.7 to get signal-handling fixes
_commit=71630de57f02f50e10caa436ea098f9cb506e60a
pkgrel=3
pkgdesc='maildir and IMAP processor/filter using Python as its configuration language'
arch=('any')
url='https://mailprocessing.github.io/mailprocessing/'
license=('GPL-2.0-or-later')
depends=('python')
makedepends=(python-build python-installer python-setuptools python-wheel pandoc python-pandocfilters)
source=("https://pypi.python.org/packages/source/${pkgname:0:1}/${pkgname}/${pkgname}-${pkgver}.tar.gz")

makedepends+=(git)
source=("git+https://github.com/mailprocessing/mailprocessing.git#commit=${_commit}")

md5sums=('05d553eef4f1149e165fce18b0e9c576')
sha256sums=('3ee38feb913780b780f0fb048ba4b0a74617f3692de419de62fc94a1fa8093b5')

replaces=('maildirproc')
conflicts=('maildirproc')

pkgver() {
  cd $pkgname*
  git describe --long --tags | sed -E 's/-([0-9]+)-g/.r\1.g/'
}

prepare() {
  cd $pkgname*
  make -C docs clean
}

build() {
  cd $pkgname*
  python -m build --wheel --no-isolation
  make -C docs
}

package() {
  _python_version=$(pacman -S --print-format='%v' python|cut -d- -f1|cut -d. -f1,2)
  depends+=("python>=${_python_version}" "python<${_python_version%.*}.$(( ${_python_version##*.} + 1 ))")

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

  install -Dm644 -t "$pkgdir"/usr/share/man/man1/ docs/*.1
  install -Dm644 -t "$pkgdir"/usr/share/man/man5/ docs/*.5
  install -Dm644 -t "$pkgdir"/usr/share/doc/$pkgname/ docs/*.html
  cp -r -t "$pkgdir"/usr/share/doc/$pkgname/ docs/examples
}
