# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=manhole
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=1.8.0
pkgrel=4
pkgdesc="Debugging manhole for python applications (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/ionelmc/python-manhole'
msys2_references=(
  'pypi: manhole'
)
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest"
              "${MINGW_PACKAGE_PREFIX}-python-requests"
              #"${MINGW_PACKAGE_PREFIX}-python-process-tests"
              #"${MINGW_PACKAGE_PREFIX}-python-virtualenv"
             )
options=('staticlibs' 'strip' '!debug')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/ionelmc/python-manhole/archive/v$pkgver.tar.gz")
sha512sums=('041452d602895f7ceaafc74ac50713acd470120b022a942946de83f90d2d839ee15b333dfc329f88597b13e0b3fee436af526beae95a3ff94e51376fd2cc27e6')

prepare() {
  rm -rf python-build-${CARCH} || true
  cp -r "python-${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  msg "Python build for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

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

  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    # Remove shebang line
    sed -e '1 { s/^#!.*$// }' -i "${_f}"
  done
}
