# Maintainer: Joel Holdsworth <jholdsworth@nvidia.com>

_realname=bottle
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.13.4
pkgrel=1
pkgdesc="A fast and simple python micro-framework for small web-applications (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: python-bottle'
  'purl: pkg:pypi/bottle'
  "cpe: cpe:/a:bottlepy:bottle"
)
msys2_repository_url='https://github.com/bottlepy/bottle'
msys2_changelog_url='https://bottlepy.org/docs/dev/changelog.html'
msys2_documentation_url='https://bottlepy.org/docs/dev/index.html'
msys2_issue_tracker_url='https://github.com/bottlepy/bottle/issues'
url='https://bottlepy.org/'
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('787e78327e12b227938de02248333d788cfe45987edca735f8f88e03472c3f47')

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

  # Undo path translation
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*.py; do
    sed -e '1 { s/^#!.*python.*$/#!\/usr\/bin\/env python3/ }' -i ${_f}
  done

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