# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=pyalpm
pkgbase="python-${_realname}"
pkgname=("python-${_realname}")
pkgver=0.10.10
pkgrel=3
pkgdesc="Libalpm bindings for Python"
arch=('i686' 'x86_64')
license=('GPL')
url="https://gitlab.archlinux.org/archlinux/pyalpm"
msys2_references=(
  'archlinux: pyalpm'
  "purl: pkg:pypi/pyalpm"
)
depends=("python" "libarchive" "libgpgme")
makedepends=('gettext-devel'
             'heimdal-devel'
             'libarchive-devel'
             'libcurl-devel'
             'libgpgme-devel'
             'python-setuptools'
             'python-installer'
             'python-build'
             'pacman'
             'gcc'
             'git'
             'python-pkgconfig')
provides=("python3-${_realname}")
conflicts=("python3-${_realname}")
replaces=("python3-${_realname}")
source=("git+https://gitlab.archlinux.org/archlinux/pyalpm.git#tag=${pkgver}"
        "0005-Use-pkg-config-add-LIBALPM_STATIC-env.-var.patch"
        "https://gitlab.archlinux.org/archlinux/pyalpm/-/commit/1564f173af70d9fc103885613f5a6e7d8947983e.patch")
sha256sums=('94c6ac10e4f1fa69f97550fab89b18ec1ecd75a749d7df364e784f951cebb9dd'
            'e26201c95cf6511cc884a38a8ca17cd61154542c390bcd8f7484bdc8e560cee9'
            '3a4f5cf2f7b79cdac95d5968adb7a75e6f08f20df2cd48a582576ddf054e56b3')

prepare() {
  cd "${srcdir}/${_realname}"

  patch -p1 -i "${srcdir}"/0005-Use-pkg-config-add-LIBALPM_STATIC-env.-var.patch
  patch -p1 -i "${srcdir}"/1564f173af70d9fc103885613f5a6e7d8947983e.patch

  # The git repo uses symlinks in the scripts folder to
  # the actual source files in the pycman folder. Patch
  # files created by git will therefore not contain any
  # changes to the files in scripts so copy the patched
  # ones across now.
  pushd "${srcdir}"/${_realname}
    for _file in database deptest query remove sync upgrade version; do
      cp -f pycman/action_${_file}.py scripts/pycman-${_file}
    done
  popd
}

build() {
  cd "${srcdir}/${_realname}"

  LIBALPM_STATIC=1 \
    python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/${_realname}"

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