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

_realname=poetry
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=1.6.1
pkgrel=3
pkgdesc="Python dependency management and packaging made easy (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
msys2_references=(
  'pypi: poetry'
)
url="https://github.com/python-poetry/poetry"
options=('!strip')
license=('spdx:MIT')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python"
  "${MINGW_PACKAGE_PREFIX}-python-poetry-core"
  "${MINGW_PACKAGE_PREFIX}-python-poetry-plugin-export"
  "${MINGW_PACKAGE_PREFIX}-python-build"
  "${MINGW_PACKAGE_PREFIX}-python-cachecontrol"
  "${MINGW_PACKAGE_PREFIX}-python-cleo"
  "${MINGW_PACKAGE_PREFIX}-python-crashtest"
  "${MINGW_PACKAGE_PREFIX}-python-dulwich"
  "${MINGW_PACKAGE_PREFIX}-python-filelock"
  "${MINGW_PACKAGE_PREFIX}-python-html5lib"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
  "${MINGW_PACKAGE_PREFIX}-python-jsonschema"
  "${MINGW_PACKAGE_PREFIX}-python-keyring"
  "${MINGW_PACKAGE_PREFIX}-python-lockfile"
  "${MINGW_PACKAGE_PREFIX}-python-packaging"
  "${MINGW_PACKAGE_PREFIX}-python-pexpect"
  "${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"
  "${MINGW_PACKAGE_PREFIX}-python-urllib3"
)
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        "8400.patch")
sha256sums=('0ab9b1a592731cc8b252b8d6aaeea19c72cc0a109d7468b829ad57e6c48039d2'
            '11d63a1f5427d5f8619507b382c943fd02ed0cd8d9d415ae83fd26c8a8b1e6f0')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  # Fix jsonschema version limitation
  # It is only restricted because of the rust build dependency, which we don't mind
  # https://github.com/python-poetry/poetry/pull/8161
  sed -e 's|jsonschema = ">=4.10.0,<4.18.0"|jsonschema = ">=4.19.0"|g' -i pyproject.toml

  # https://github.com/python-poetry/poetry/pull/8400
  patch -p1 -i "${srcdir}/8400.patch"
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"

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

package() {
  cd "${srcdir}/${_realname}-${pkgver}"

  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
}
