# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=tox
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=3.21.2
pkgrel=3
pkgdesc="Python virtualenv management and testing tool (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://tox.readthedocs.io"
license=('GPL2')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-py"
         "${MINGW_PACKAGE_PREFIX}-python-six"
         "${MINGW_PACKAGE_PREFIX}-python-virtualenv"
         "${MINGW_PACKAGE_PREFIX}-python-setuptools"
         "${MINGW_PACKAGE_PREFIX}-python-setuptools-scm"
         "${MINGW_PACKAGE_PREFIX}-python-filelock"
         "${MINGW_PACKAGE_PREFIX}-python-toml"
         "${MINGW_PACKAGE_PREFIX}-python-pluggy")
makedepends=("util-linux")
options=('staticlibs' 'strip' '!debug')
source=("${_realname}-${pkgver}.tar.gz"::"https://pypi.io/packages/source/t/tox/${_realname}-${pkgver}.tar.gz")
sha256sums=('f501808381c01c6d7827c2f17328be59c0a715046e94605ddca15fb91e65827d')

prepare() {
  find ${_realname}-${pkgver} -name "*.pyc" -delete
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

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

#This hangs when I try this.
#check() {
#  cd "${srcdir}/python-build-${CARCH}" 
#  msg "Python build for ${CARCH}" 
#  ${MINGW_PREFIX}/bin/virtualenv "$srcdir/pyvenv" --system-site-packages
#  . "$srcdir/pyvenv/bin/activate"
#  ${MINGW_PREFIX}/bin/python setup.py install
#  ${MINGW_PREFIX}/bin/python setup.py pytest
#
#}

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}/COPYING"

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