# Maintainer: Filipe Laíns (FFY00) <lains@archlinux.org>

pkgname=liquidctl
pkgver=1.15.0
pkgrel=1
arch=('any')
url='https://github.com/liquidctl/liquidctl'
license=('GPL3')
pkgdesc='Cross-platform CLI and Python drivers for AIO liquid coolers and other devices'
depends=('python' 'python-docopt' 'python-pyusb' 'python-hidapi' 'python-colorlog' 'i2c-tools' 'python-pillow' 'python-crcmod')
makedepends=('git' 'python-setuptools-scm' 'python-build' 'python-installer' 'python-wheel')
checkdepends=('python-pytest')
source=("git+$url.git?signed#tag=v$pkgver")
validpgpkeys=('23F335ED4E829797734B22F65841AF7406AF7AD0') # Jonas Tadeu Silva Malaco Filho <jonas@jonasmalaco.com>
sha512sums=('e596460ea831a787068530533de1e5352f46e701d7a2d6bee7dbf791403b6b480afb0a4da8d50da3600771dcfe8b7d9d5cf01598246a651a204e3ca9bc1243a2')

prepare() {
  cd "${pkgname}"
  #/ https://github.com/liquidctl/liquidctl/commit/c50afa4e610bd2e268e85c347e2644794c817a78
  git cherry-pick -n -m1 c50afa4e610bd2e268e85c347e2644794c817a78
}

build() {
  cd "${pkgname}"

  export DIST_NAME='Arch Linux'
  export DIST_PACKAGE="$pkgver-$pkgrel"
  export SETUPTOOLS_SCM_PRETEND_VERSION="$pkgver"

  python -m build --wheel --no-isolation
}

check() {
  cd "${pkgname}"

  mkdir runtime
  XDG_RUNTIME_DIR=runtime python -m pytest
}

package() {
  cd "${pkgname}"

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

  install -Dm 644 extra/linux/71-liquidctl.rules "${pkgdir}"/usr/lib/udev/rules.d/71-liquidctl.rules

  # Install documentation
  install -dm 755 "${pkgdir}"/usr/share/doc/"${pkgname}"
  cp -r -a --no-preserve=ownership docs/* "${pkgdir}"/usr/share/doc/"${pkgname}"
  install -Dm 644 liquidctl.8 "${pkgdir}"/usr/share/man/man8/liquidctl.8
}
