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

_realname=virtualenv
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-virtualenv")
pkgver=20.4.7
pkgrel=1
pkgdesc="Virtual Python Environment builder (mingw-w64)"
url="https://virtualenv.pypa.io/"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python-appdirs"
         "${MINGW_PACKAGE_PREFIX}-python-distlib"
         "${MINGW_PACKAGE_PREFIX}-python-filelock"
         "${MINGW_PACKAGE_PREFIX}-python-six")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools-scm")
source=(${_realname}-${pkgver}.tar.gz::https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz)
sha256sums=('14fdf849f80dbb29a4eb6caa9875d476ee2a5cf76a5f5415fa2f1606010ab467')

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

  ${MINGW_PREFIX}/bin/python setup.py build
}

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

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1

  local PREFIX_WIN=$(cygpath -wm ${MINGW_PREFIX})
  # fix python command in files
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*.py; do
    sed -i 's/\#\!.*//' $_f
  done
  install -Dm644 LICENSE -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
