# Maintainer: @naveen521kk on Github, Naveen M K <naveen521kk@gmail.com>

_pyname=cookiecutter
_realname=cookiecutter
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.6.0
pkgrel=3
pkgdesc='A command-line utility that creates projects from project templates, e.g. creating a Python package project from a Python package project template. (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: python-cookiecutter'
  'purl: pkg:pypi/cookiecutter'
  "cpe: cpe:/a:cookiecutter_project:cookiecutter"
)
msys2_documentation_url='https://cookiecutter.readthedocs.io/'
url="https://github.com/cookiecutter/cookiecutter"
license=('spdx:BSD-3-Clause')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python"
  "${MINGW_PACKAGE_PREFIX}-python-arrow"
  "${MINGW_PACKAGE_PREFIX}-python-binaryornot"
  "${MINGW_PACKAGE_PREFIX}-python-jinja"
  "${MINGW_PACKAGE_PREFIX}-python-click"
  "${MINGW_PACKAGE_PREFIX}-python-yaml"
  "${MINGW_PACKAGE_PREFIX}-python-slugify"
  "${MINGW_PACKAGE_PREFIX}-python-requests"
  "${MINGW_PACKAGE_PREFIX}-python-rich"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-python-build"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
  "${MINGW_PACKAGE_PREFIX}-python-setuptools"
)
checkdepends=(
  "${MINGW_PACKAGE_PREFIX}-python-freezegun"
  "${MINGW_PACKAGE_PREFIX}-python-pytest"
  "${MINGW_PACKAGE_PREFIX}-python-pytest-mock"
)
options=('!strip')
source=("https://pypi.org/packages/source/${_pyname::1}/${_pyname}/${_pyname}-${pkgver}.tar.gz")
sha256sums=('db21f8169ea4f4fdc2408d48ca44859349de2647fbe494a9d6c3edfc0542c21c')

prepare() {
  # we do not care about code coverage in pytest runs
  sed -e '/addopts/d' -i "${_pyname//_/-}-$pkgver"/setup.cfg
}

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}"
  PYTHONPATH="build:$PYTHONPATH" ${MINGW_PREFIX}/bin/pytest -vv || warning "Tests failed"
}

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 "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
