# Maintainer: Sarah Ottinger

_realname=service_identity
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=21.1.0
pkgrel=1
pkgdesc='Making it easy to write async iterators (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://service-identity.readthedocs.io/"
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python-attrs" "${MINGW_PACKAGE_PREFIX}-python-idna" "${MINGW_PACKAGE_PREFIX}-python-pyasn1-modules" "${MINGW_PACKAGE_PREFIX}-python-six")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest" "${MINGW_PACKAGE_PREFIX}-python-cryptography")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools" "${MINGW_PACKAGE_PREFIX}-python-sphinx")
source=("https://github.com/pyca/service_identity/archive/${pkgver}.tar.gz")
sha256sums=('541294ad6060c10e28554f36bb1c154e11f71ad3e23a160eea62eff9bf50522c')

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
  ${MINGW_PREFIX}/bin/sphinx-build -b text docs docs/_build/text
  ${MINGW_PREFIX}/bin/sphinx-build -b man docs docs/_build/man
}

check() {
  cd "${srcdir}/python-build-${CARCH}"
  PYTHONPATH=src ${MINGW_PREFIX}/bin/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
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
  install -Dm 644 README.rst -t "${pkgdir}${MINGW_PREFIX}/share/doc/python-${_realname}"
  install -Dm 644 docs/_build/text/*.txt -t "${pkgdir}${MINGW_PREFIX}/share/doc/python-${_realname}"
  install -Dm 644 docs/_build/man/service-identity.1 "${pkgdir}${MINGW_PREFIX}/share/man/man1/service-identity.1"
}
