# Maintainer: Smo <smo@xpra.org>

_realname=zeroconf
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}"  "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=0.21.3
pkgrel=2
pkgdesc="A pure python implementation of multicast DNS service discovery (mingw-w64)"
arch=('any')
url='https://github.com/jstasiak/python-zeroconf'
license=('GPLv2')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python2-ifaddr"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python2-typing"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-python3-ifaddr"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools")
options=('staticlibs' 'strip' '!debug')
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/jstasiak/python-zeroconf/archive/${pkgver}.tar.gz")
sha512sums=('2d42baf12bc44c05c45a8491d840422e8596d9748d8292d52d45a8cce559b867485174d99204826c7ea1d92711133c2b2e7082cea175dd00017c0e959845e611')

prepare() {
  cd "${srcdir}"
  for builddir in python{2,3}-build-${CARCH}; do
    rm -rf ${builddir} | true
    cp -r "python-${_realname}-${pkgver}" "${builddir}"
  done
  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver
}

build() {
  for pver in {2,3}; do  
    msg "Python ${pver} build for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done  
}

check() {
#    msg "Python 2 test for ${CARCH}"
#    cd "${srcdir}/python2-build-${CARCH}"
#    ${MINGW_PREFIX}/bin/py.test2 . || warning "Tests failed"

    msg "Python 3 test for ${CARCH}"
    cd "${srcdir}/python3-build-${CARCH}"
    ${MINGW_PREFIX}/bin/py.test . || warning "Tests failed"

}

package_python3-zeroconf() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3"
           "${MINGW_PACKAGE_PREFIX}-python3-ifaddr")

  cd "${srcdir}/python3-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 COPYING "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/COPYING"
}

package_python2-zeroconf() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2"
           "${MINGW_PACKAGE_PREFIX}-python2-ifaddr"
           "${MINGW_PACKAGE_PREFIX}-python2-typing")

  cd "${srcdir}/python2-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 COPYING "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/COPYING"
}

package_mingw-w64-i686-python2-zeroconf() {
  package_python2-zeroconf
}

package_mingw-w64-i686-python3-zeroconf() {
  package_python3-zeroconf
}

package_mingw-w64-x86_64-python2-zeroconf() {
  package_python2-zeroconf
}

package_mingw-w64-x86_64-python3-zeroconf() {
  package_python3-zeroconf
}
