# Maintainer: Some One <some.one@some.email.com>
#This value is here because some python package names have capital letters
#while there is a strong preference for lowercase letters in ArchLinux and
#MSYS packages.

_realname=oslo-db
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=8.5.0
pkgrel=1
pkgdesc="OpenStack Database Pattern Library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://pypi.python.org/pypi/oslo.db'
license=('LICENSE')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-six"
         "${MINGW_PACKAGE_PREFIX}-python-pbr"
         "${MINGW_PACKAGE_PREFIX}-python-alembic"
         "${MINGW_PACKAGE_PREFIX}-python-debtcollector"
         "${MINGW_PACKAGE_PREFIX}-python-oslo-i18n"
         "${MINGW_PACKAGE_PREFIX}-python-oslo-config"
         "${MINGW_PACKAGE_PREFIX}-python-oslo-utils"
         "${MINGW_PACKAGE_PREFIX}-python-sqlalchemy"
         "${MINGW_PACKAGE_PREFIX}-python-sqlalchemy-migrate"
         "${MINGW_PACKAGE_PREFIX}-python-stevedore")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-mock"
              "${MINGW_PACKAGE_PREFIX}-python-testrepository"
              "${MINGW_PACKAGE_PREFIX}-python-testresources"
              "${MINGW_PACKAGE_PREFIX}-python-oslotest"
              "${MINGW_PACKAGE_PREFIX}-python-oslo-context")
options=('staticlibs' 'strip' '!debug')
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/openstack/oslo.db/archive/${pkgver}.tar.gz")
sha512sums=('443ef7602635191b07cdf2620086a5119f7a2b76a9cf1a8d1b9999c16ef08217aea7b403305b78262e37ed8e13ca016b997c9157da3ef08b241af2da758c6eba')

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

del_file_exists() {
  for _fname in "$@"
  do
    if [ -f $_fname ]; then
      rm -rf $_fname
    fi
  done
}
# =========================================== #

prepare() {
  cd "${srcdir}/oslo.db-${pkgver}"
  sed -i 's/import unittest2/import unittest as unittest2/' oslo_db/tests/sqlalchemy/test_async_eventlet.py

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

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

check() {
  cd "${srcdir}/oslo.db-${pkgver}"
  PYTHON=python ${MINGW_PREFIX}/bin/python setup.py testr || warning "tests failed"
}

package() {
  cd "${srcdir}/oslo.db-${pkgver}"

  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
}
