# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.su>

_realname=twine
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=6.2.0
pkgrel=1
pkgdesc='Collection of utilities for interacting with PyPI (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://twine.readthedocs.io/'
msys2_repository_url='https://github.com/pypa/twine'
msys2_changelog_url='https://twine.readthedocs.io/en/stable/changelog.html'
msys2_references=(
  'archlinux: twine'
  'gentoo: dev-python/twine'
  'purl: pkg:pypi/twine'
)
license=('Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-id"
         "${MINGW_PACKAGE_PREFIX}-python-pkginfo"
         "${MINGW_PACKAGE_PREFIX}-python-readme-renderer"
         "${MINGW_PACKAGE_PREFIX}-python-requests"
         "${MINGW_PACKAGE_PREFIX}-python-requests-toolbelt"
         "${MINGW_PACKAGE_PREFIX}-python-urllib3"
         "${MINGW_PACKAGE_PREFIX}-python-importlib-metadata"
         "${MINGW_PACKAGE_PREFIX}-python-keyring"
         "${MINGW_PACKAGE_PREFIX}-python-packaging"
         "${MINGW_PACKAGE_PREFIX}-python-rfc3986"
         "${MINGW_PACKAGE_PREFIX}-python-rich")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-wheel"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools-scm"
             "${MINGW_PACKAGE_PREFIX}-python-installer")
provides=("${MINGW_PACKAGE_PREFIX}-python-twine")
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('e5ed0d2fd70c9959770dce51c8f39c8945c574e18173a7b81802dab51b4b75cf')

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

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

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

  python -m build --wheel --skip-dependency-check --no-isolation
}

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

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

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