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

_realname=pyalpm
pkgbase="python-${_realname}"
pkgname=("python-${_realname}")
pkgver=0.10.9
pkgrel=5
pkgdesc="Libalpm bindings for Python"
arch=('i686' 'x86_64')
license=('GPL')
url="https://gitlab.archlinux.org/archlinux/pyalpm"
msys2_references=(
  'archlinux: pyalpm'
  "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")
sha256sums=('SKIP'
            'e26201c95cf6511cc884a38a8ca17cd61154542c390bcd8f7484bdc8e560cee9')

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

  patch -p1 -i "${srcdir}"/0005-Use-pkg-config-add-LIBALPM_STATIC-env.-var.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
}
