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

_realname=html5lib
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=1.1
pkgrel=6
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
pkgdesc="A Python HTML parser/tokenizer based on the WHATWG HTML5 spec (mingw-w64)"
url="https://github.com/html5lib"
msys2_references=(
  'purl: pkg:pypi/html5lib'
  "cpe: cpe:2.3:a:html5lib:html5lib"
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-six"
         "${MINGW_PACKAGE_PREFIX}-python-webencodings")
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-lxml"
              "${MINGW_PACKAGE_PREFIX}-python-mock")
_test_commit=c305da74fae50fb018870de7a042da36c1a93b65
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        "https://github.com/html5lib/html5lib-tests/archive/${_test_commit}.tar.gz")
sha256sums=('b2e5b40261e20f354d198eae92afc10d750afb487ed5e50f9c4eaf07c184146f'
            'cb261423c644b3469ac66926e290060b481371d0952995d270492fc761d0209a')

prepare() {
  cd "${srcdir}"/"${_realname}-${pkgver}"
  rm -rf html5lib/tests/testdata
  cp -r "${srcdir}/html5lib-tests-${_test_commit}" html5lib/tests/testdata
}

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}
  ${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 -Dm755 LICENSE "${pkgdir}"${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE
}
