# 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.3.0
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
)
optdepends=(
  'ipython: netaddr interractive command support'
)
options=('!makeflags')
source=(https://github.com/drkjam/${_pyname}/archive/${pkgver}/${pkgname}-${pkgver}.tar.gz)
sha512sums=('93ac74f2ad6ddd300da25aded4ae4e3dc71bb52b6447dcbefefa55a0b8a26f55290594a88cd1f557548026f3d4673a1edc6ad19cbf274da6d2783d4907f931e5')
b2sums=('42b49dbd95f0f09826a1d17042482cfcb4b69fb38d6c300f3b3acf0050484f077d5b43750a9c16217477cd6268ad692ca143521575348241cd42e2aec9d83ce5')

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:
