# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=poetry
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.1.4
pkgrel=1
pkgdesc="Python dependency management and packaging made easy (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://python-poetry.org/'
msys2_repository_url='https://github.com/python-poetry/poetry'
msys2_references=(
  'purl: pkg:pypi/poetry'
  "cpe: cpe:/a:python-poetry:poetry"
)
license=('spdx:MIT')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python"
  "${MINGW_PACKAGE_PREFIX}-python-poetry-core"
  "${MINGW_PACKAGE_PREFIX}-python-build"
  "${MINGW_PACKAGE_PREFIX}-python-cachecontrol"
  "${MINGW_PACKAGE_PREFIX}-python-cleo"
  "${MINGW_PACKAGE_PREFIX}-python-dulwich"
  "${MINGW_PACKAGE_PREFIX}-python-fastjsonschema"
  "${MINGW_PACKAGE_PREFIX}-python-findpython"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
  "${MINGW_PACKAGE_PREFIX}-python-keyring"
  "${MINGW_PACKAGE_PREFIX}-python-packaging"
  "${MINGW_PACKAGE_PREFIX}-python-pbs-installer"
  "${MINGW_PACKAGE_PREFIX}-python-pkginfo"
  "${MINGW_PACKAGE_PREFIX}-python-platformdirs"
  "${MINGW_PACKAGE_PREFIX}-python-pyproject-hooks"
  "${MINGW_PACKAGE_PREFIX}-python-requests"
  "${MINGW_PACKAGE_PREFIX}-python-requests-toolbelt"
  "${MINGW_PACKAGE_PREFIX}-python-shellingham"
  "${MINGW_PACKAGE_PREFIX}-python-tomlkit"
  "${MINGW_PACKAGE_PREFIX}-python-trove-classifiers"
  "${MINGW_PACKAGE_PREFIX}-python-virtualenv"
)
optdepends=(
  "${MINGW_PACKAGE_PREFIX}-python-poetry-plugin-export: provides an export command"
  "${MINGW_PACKAGE_PREFIX}-python-poetry-plugin-shell: provides the shell command"
)
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        "0001-allow-virtualenv.patch")
sha256sums=('bed4af5fc87fb145258ac5b1dae77de2cd7082ec494e3b2f66bca0f477cbfc5c'
            '9becb9064e6e6667f8efeac2868f8895cb880220731a989544b21a8a7ad2d2e6')

prepare() {
  cd "${_realname}-${pkgver}"
  sed -e 's/\^/>=/g' -e 's/~=/>=/g' -i pyproject.toml

  # https://github.com/python-poetry/poetry/pull/10506
  patch -p1 -i "${srcdir}/0001-allow-virtualenv.patch"
}

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

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