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

_realname=jaraco.envs
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.6.0
pkgrel=2
pkgdesc='Classes for orchestrating Python (virtual) environments (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://pypi.org/project/jaraco.envs/"
msys2_references=(
  'purl: pkg:pypi/jaraco-envs'
)
license=('spdx:MIT')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python"
  "${MINGW_PACKAGE_PREFIX}-python-path"
  "${MINGW_PACKAGE_PREFIX}-python-virtualenv"
  "${MINGW_PACKAGE_PREFIX}-python-tox"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-python-build"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
  "${MINGW_PACKAGE_PREFIX}-python-setuptools"
  "${MINGW_PACKAGE_PREFIX}-python-setuptools-scm"
)
source=(
  "https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
  "0001-mingw-python-fix.patch"
)
sha256sums=('809195c406640db256ee01eebf4f6a369dd85759d8178c3921704308dd0360f5'
            '73ad74505c0cc0cc0a07e1f69b6ad045d62dc50011cfa847e023745510332270')

prepare() {
  pushd "${_realname//_/-}-$pkgver"
  patch -p1 -i "${srcdir}"/0001-mingw-python-fix.patch
  popd
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname//_/-}-$pkgver" "python-build-${MSYSTEM}"
}

build() {
  cd "${srcdir}/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 || 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"
}
