# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>.

_realname=netaddr
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=1.3.0
pkgrel=1
pkgdesc="Pure Python network address representation and manipulation library (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'purl: pkg:pypi/netaddr'
)
msys2_repository_url='https://github.com/netaddr/netaddr'
url='https://netaddr.readthedocs.io/'
license=('spdx:BSD-3-Clause-Clear')
depends=("${MINGW_PACKAGE_PREFIX}-python")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-ipython: netaddr interractive command support")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest"
              "${MINGW_PACKAGE_PREFIX}-python-pytest-cov")
options=(!strip)
source=(https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz)
sha256sums=('5c3c3d9895b551b763779ba7db7a03487dc1f8e3b385af819af341ae9ef6e48a')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  sed -r 's|#!/usr/bin/env python||g' -i netaddr/eui/ieee.py netaddr/ip/iana.py
  }

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  LC_ALL='en_US.UTF-8' ${MINGW_PREFIX}/bin/py.test
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm 644 LICENSE.rst "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE.rst"
}
