# Maintainer: Zvi Baratz <22370149+ZviBaratz@users.noreply.github.com>
#
# The AUR's copy of this file is pushed by hand at each release; see the README's Development section. CI builds,
# installs and removes it on Arch (.github/scripts/check-aur-package.sh).

pkgname=duotape
pkgver=0.1.0
pkgrel=1
pkgdesc="Start-anytime local meeting recorder: one toggle, separate speaker tracks, local transcripts"
arch=(any)
url="https://github.com/ZviBaratz/duotape"
license=(Apache-2.0)
# The .deb's dependencies in Arch's names (tests/test_aur_package.py), plus bash, which Debian never lists, and the
# icon theme that holds the icons' folders.
depends=(python python-gobject glib2 ffmpeg pipewire pipewire-pulse wireplumber systemd libnotify bash
  hicolor-icon-theme)
optdepends=(
  'obs-studio: screen video (experimental)'
  'xdg-utils: open the recordings folder when no file manager answers over D-Bus'
)
makedepends=(python-build python-installer python-hatchling)
checkdepends=(python-pytest)
source=("https://files.pythonhosted.org/packages/source/${pkgname::1}/$pkgname/$pkgname-$pkgver.tar.gz")
# Set from the published sdist at each release (updpkgsums): the sdist is dated from its commit, so its sum is known
# only once the release is built.
sha256sums=('SKIP')

build() {
  cd "$pkgname-$pkgver"
  python -m build --wheel --no-isolation
}

check() {
  cd "$pkgname-$pkgver"
  # Tests that need a tool this machine lacks skip.
  python -m pytest -q -p no:cacheprovider
}

package() {
  cd "$pkgname-$pkgver"
  # installer byte-compiles the modules, as Arch's own Python packages are.
  python -m installer --destdir="$pkgdir" dist/*.whl

  # The launcher entry for every user, rendered by duotape's own code for the installed command, with no language
  # actions: `duotape install-desktop` writes a per-user entry with yours, which takes precedence.
  install -d "$pkgdir/usr/share/applications"
  python -I -B -c '
import sys
from pathlib import Path

sys.path.insert(0, "src")
from duotape.desktop_entry import render_desktop_entry

template_text = Path("src/duotape/data/duotape.desktop.in").read_text(encoding="utf-8")
sys.stdout.write(render_desktop_entry(template_text, Path("/usr/bin/duotape"), []))
' >"$pkgdir/usr/share/applications/$pkgname.desktop"
  install -Dm644 -t "$pkgdir/usr/share/icons/hicolor/scalable/apps" src/duotape/data/icons/*.svg

  install -Dm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE NOTICE
}
