# Maintainer: Sarah Ottinger

_realname=flask
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.0.1
pkgrel=1
pkgdesc='Micro webdevelopment framework for Python (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="http://flask.pocoo.org/"
license=('custom:BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python-click" "${MINGW_PACKAGE_PREFIX}-python-itsdangerous" "${MINGW_PACKAGE_PREFIX}-python-jinja" "${MINGW_PACKAGE_PREFIX}-python-werkzeug")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=("${_realname}-$pkgver.tar.gz::https://github.com/pallets/flask/archive/${pkgver}.tar.gz")
sha256sums=('11e4f01661f8a8c4895993d4b777dbd56a02ae3e2f36740e2a21d9a2508a1fc9')

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

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

check() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py test || warning "Tests failed"
}

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

  local _PREFIX_WIN=$(cygpath -m ${MINGW_PREFIX})
  sed -s "s|${_PREFIX_WIN}/bin/||g" -i "${pkgdir}${MINGW_PREFIX}/bin/flask-script.py"

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