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

_realname=fonttools
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.24.4
pkgrel=1
pkgdesc="Converts OpenType and TrueType fonts to and from XML (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='https://github.com/fonttools/fonttools'
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-brotli: WOFF 1.0 and WOFF 2.0 webfonts"
            "${MINGW_PACKAGE_PREFIX}-python-pyfilesystem2: for fontTools.ufoLib: to read/write UFO fonts"
            "${MINGW_PACKAGE_PREFIX}-python-pyzopfli: WOFF 1.0 and WOFF 2.0 webfonts"
            "${MINGW_PACKAGE_PREFIX}-python-sympy: for fontTools.misc.symfont, module for symbolic font statistics analysis")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-matplotlib"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest-runner")
options=('staticlibs' 'strip' '!debug')
source=("${_realname}-${pkgver}.zip::https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.zip")
sha256sums=('df7fab667b039cd2a00a1fffcba73a32b2c630ef2a12ab7069ef6df5333f20c3')

prepare() {
  rm -rf python-build-${CARCH}
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  msg "Python build for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python setup.py build
}

#Enable tests when the dependencies are solved
check() {
  msg "Python test for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py pytest || warning "Tests failed"
}

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

  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    sed -e '1 { s/^#!.*$// }' -i ${_f}
  done

  install -D -m755 LICENSE "${pkgdir}${MINGW_PREFIX}"/share/licenses/python-${_realname}/LICENSE
  chmod oga+r "${pkgdir}${MINGW_PREFIX}"/share/man/man1/ttx.1
}
