# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=sqlalchemy-migrate
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=0.13.0
pkgrel=2
pkgdesc="Database schema migration for SQLAlchemy (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://pypi.python.org/pypi/sqlalchemy-migrate'
license=('Apache')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-six"
         "${MINGW_PACKAGE_PREFIX}-python-pbr"
         "${MINGW_PACKAGE_PREFIX}-python-sqlalchemy"
         "${MINGW_PACKAGE_PREFIX}-python-decorator"
         "${MINGW_PACKAGE_PREFIX}-python-sqlparse"
         "${MINGW_PACKAGE_PREFIX}-python-tempita")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
#checkdepends=("${MINGW_PACKAGE_PREFIX}-python-mock"
#             "${MINGW_PACKAGE_PREFIX}-python-testrepository"
#             "${MINGW_PACKAGE_PREFIX}-python-scripttest"
#             "${MINGW_PACKAGE_PREFIX}-python-ibm-db-sa"
#             "${MINGW_PACKAGE_PREFIX}-mysql-python")
options=('staticlibs' 'strip' '!debug')
source=(#"${_realname}-${pkgver}.tar.gz"::"https://github.com/openstack/sqlalchemy-migrate/archive/${pkgver}.tar.gz"
        https://files.pythonhosted.org/packages/36/bb/40f66b12b18fb03da76dcee31df75cca9e54b71d9d8a784bb95bfbadee2c/${_realname}-${pkgver}.tar.gz)
sha512sums=('1ca826a5d80c1373ffc4b2366dfb6d5dd24204964462873451c97d8ff4d75fc6c63f663c4769b7f6cc00002f6a98d425f41d759e5c010b4b81a8b74ffbb102b6')

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

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
  export PBR_VERSION=${pkgver}
}

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

#check() {
#  cd "${srcdir}/python-build-${CARCH}"
#  ${MINGW_PREFIX}/bin/python setup.py testr || 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

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