# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=nvchecker
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.20
pkgrel=1
pkgdesc="New version checker for software releases (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/lilydjwg/nvchecker"
msys2_references=(
  'archlinux: nvchecker'
  'purl: pkg:pypi/nvchecker'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-structlog"
         "${MINGW_PACKAGE_PREFIX}-python-platformdirs"
         "${MINGW_PACKAGE_PREFIX}-python-tornado"
         "${MINGW_PACKAGE_PREFIX}-python-pycurl")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-docutils"
             "${MINGW_PACKAGE_PREFIX}-python-pygments"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest"
              "${MINGW_PACKAGE_PREFIX}-python-pytest-asyncio"
              "${MINGW_PACKAGE_PREFIX}-python-flaky"
              "${MINGW_PACKAGE_PREFIX}-python-lxml")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-lxml: for the htmlparser source"
            "${MINGW_PACKAGE_PREFIX}-python-packaging: for the pypi source"
            "${MINGW_PACKAGE_PREFIX}-python-gobject: for nvchecker-notify"
            "${MINGW_PACKAGE_PREFIX}-python-awesomeversion: for sorting versions"
            "${MINGW_PACKAGE_PREFIX}-python-zstandard: for the rpmrepo source"
            "${MINGW_PACKAGE_PREFIX}-libnotify: for nvchecker-notify"
            "git: support for git repositories")
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('79cfc9eba3170405db5b1d74475f2e0b539d708c869a7212b40e803e033e0149')

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  "${MINGW_PREFIX}"/bin/python -m pytest
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE -t "$pkgdir"${MINGW_PREFIX}/share/licenses/$_realname

  for _f in ini2toml notify; do
    # Remove shebang line
    sed -e '1 { s/^#!.*$// }' -i "${pkgdir}${MINGW_PREFIX}/bin/nvchecker-${_f}"
  done
}
