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

_realname=beautifulsoup4
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=4.9.3
pkgrel=1
pkgdesc="A Python HTML/XML parser designed for quick turnaround projects like screen-scraping (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://www.crummy.com/software/BeautifulSoup/index.html"
license=('PSF')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-soupsieve")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-chardet: to autodetect character encodings"
            "${MINGW_PACKAGE_PREFIX}-python-lxml: alternative HTML parser"
            "${MINGW_PACKAGE_PREFIX}-python-html5lib: alternative HTML parser")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest")
source=("https://www.crummy.com/software/BeautifulSoup/bs4/download/${pkgver%.*}/${_realname}-${pkgver}.tar.gz"
        #https://files.pythonhosted.org/packages/86/cd/495c68f0536dcd25f016e006731ba7be72e072280305ec52590012c1e6f2/beautifulsoup4-${pkgver}.tar.gz
        )
sha256sums=('84729e322ad1d5b4d25f805bfa05b902dd96450f43842c4e99067d5e1369eb25')
noextract=("${_realname}-${pkgver}.tar.gz")

prepare() {
  cd "${srcdir}"
  [[ -d ${_realname}-${pkgver} ]] && rm -rf ${_realname}-${pkgver}
  tar -xzf "${_realname}-${pkgver}.tar.gz" -C ${srcdir} || true

  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
}

check() {
  msg "Python test for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/2to3 -w bs4
  ${MINGW_PREFIX}/bin/py.test
}

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
}
