# Maintainer: Alexandre Ferreira <contact@alexjorgef.com>

pkgname=ansible-core
pkgver=2.19.3
pkgrel=1
pkgdesc='Radically simple IT automation platform'
arch=('any')
url='https://pypi.org/project/ansible-core'
msys2_references=(
  "cpe: cpe:/a:ansible:ansible"
  "cpe: cpe:/a:redhat:ansible"
  "cpe: cpe:/a:redhat:ansible_engine"
  "purl: pkg:pypi/ansible-core"
)
license=('spdx:GPL-3.0-or-later')
depends=('python' 'python-yaml' 'python-jinja' 'python-packaging')
provides=('python-ansible' 'ansible-base')
optdepends=(
	'sshpass: for ssh connections with password'
)
makedepends=('tar' 'python-build' 'python-installer' 'python-setuptools')
replaces=('ansible-base')
backup=('etc/ansible/ansible.cfg')
source=("https://pypi.python.org/packages/source/a/ansible-core/ansible_core-${pkgver}.tar.gz"
        "0001-ctypes-cdll-loadlibrary-msys2.patch")
sha512sums=('9d81bedcdddee19a4a76fe4bf01369241b62213c8e7af88c5eb8d55b9cfa776704651538144776012d947b267901d0221e38405f3c20c65e30f99c3c50b3b5f3'
            '9932c3dfcbfc05527b26f150ba54f2f927ed47a2ff0370108d2355fb80b07440669d7d92690fb3baaf8164852eb0ef366943a561e684cfd7ddfb8b727e2b0dce')
noextract=("${pkgname/-/_}-${pkgver}.tar.gz")

apply_patch_with_msg() {
  for _fname in "$@"
  do
    msg2 "Applying ${_fname}"
    patch -Nbp1 -i "${srcdir}"/${_fname}
  done
}

prepare() {
  tar zxf "${srcdir}/${pkgname/-/_}-${pkgver}.tar.gz" || tar zxf "${srcdir}/${pkgname/-/_}-${pkgver}.tar.gz"

  cd "${srcdir}/${pkgname/-/_}-${pkgver}"

  # Patches
  apply_patch_with_msg \
    0001-ctypes-cdll-loadlibrary-msys2.patch
}

build() {
  cd "${srcdir}/${pkgname/-/_}-${pkgver}"
  python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd ${pkgname/-/_}-${pkgver}
  python -m installer --destdir="${pkgdir}" dist/*.whl
  install -Dm644 COPYING "${pkgdir}"/usr/share/doc/${pkgname}/COPYING
}
