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

_realname=regex
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=2020.11.13
pkgrel=1
pkgdesc="Alternative python regular expression module. (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://www.regex.org/'
license=('Python')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
options=('staticlibs' 'strip' '!debug')
source=("https://files.pythonhosted.org/packages/source/r/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('83d6b356e116ca119db8e7c6fc2983289d87b27b3fac238cfe5dca529d884562')

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

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/${_realname}-${pkgver}"
  ${MINGW_PREFIX}/bin/python -c 'from regex.test.test_regex import test_main; test_main()'
}

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

  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

  sed -n '1,/^$/p' regex_2/regex.py > LICENSE
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"

  install -v -m755 -d "${pkgdir}${MINGW_PREFIX}/share/doc/python-regex"
  install -v -m644 docs/Features.html "${pkgdir}${MINGW_PREFIX}/share/doc/python-regex/"
  install -v -m644 docs/Features.rst "${pkgdir}${MINGW_PREFIX}/share/doc/python-regex/"
  install -v -m644 docs/UnicodeProperties.rst "${pkgdir}${MINGW_PREFIX}/share/doc/python-regex/"
}
