# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Sebastien LEDUC <sebastien@sleduc.fr>
# Contributor: Gilles CHAUVIN <gcnweb at gmail dot com>

pkgname=python-netaddr
_pyname=netaddr
pkgver=1.2.1
pkgrel=1
pkgdesc='Pure Python network address representation and manipulation library'
url='https://github.com/drkjam/netaddr'
arch=(any)
license=(BSD-3-Clause)
depends=(
  python
)
makedepends=(
  python-build
  python-installer
  python-wheel
  python-setuptools
  python-sphinx
  python-sphinx-issues
)
checkdepends=(
  python-pytest
  python-pytest-cov
)
optdepends=(
  'ipython: netaddr interractive command support'
)
options=('!makeflags')
source=(https://github.com/drkjam/${_pyname}/archive/${pkgver}/${pkgname}-${pkgver}.tar.gz)
sha512sums=('0e40e3fde2016c92e5a2fb2d8224826b77763b5ef95b8cb5014484dbf5336dfb60d9c01eadbab6cb96c0b2b06095f2ea82e99f87943d9ac60c1b3bc27e3d62ba')
b2sums=('1c6ee0e7fb328dc31c19c881835c764b09ad192f7b95cc844bb85f4063c2ccd94fb186028d99e43969c78aa5d00c7af8a8b2a81a9415792c1212132614655a90')

build() {
  cd ${_pyname}-${pkgver}
  python -m build --wheel --no-isolation
  make -C docs man text
}

check() {
  cd ${_pyname}-${pkgver}
  LC_ALL='en_US.UTF-8' py.test
}

package_python-netaddr() {
  cd ${_pyname}-${pkgver}

  python -m installer --destdir="${pkgdir}" dist/*.whl
  local _PYVERSION="$(python -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')"
  rm -rf "${pkgdir}/usr/lib/python${_PYVERSION}/site-packages/netaddr/tests/"

  install -Dm 644 LICENSE.rst -t "${pkgdir}/usr/share/licenses/${pkgname}"
  install -Dm 644 README.rst -t "${pkgdir}/usr/share/doc/${pkgname}"
  install -d "${pkgdir}/usr/share/doc/${pkgname}"
  cp -r docs/build/text/* -t "${pkgdir}/usr/share/doc/${pkgname}"
  install -Dm 644 docs/build/man/netaddr.1 "${pkgdir}/usr/share/man/man1/${pkgname}.1"
}

# vim: ts=2 sw=2 et:
