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

_realname=fonttools
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=4.61.1
pkgrel=1
pkgdesc="Converts OpenType and TrueType fonts to and from XML (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: python-fonttools'
  'gentoo: dev-python/fonttools'
  'purl: pkg:pypi/fonttools'
)
msys2_repository_url='https://github.com/fonttools/fonttools/'
msys2_changelog_url='https://github.com/fonttools/fonttools/blob/main/NEWS.rst'
url='https://fonttools.readthedocs.io/'
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python")
if [[ ${CARCH} != i686 ]]; then
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"
            "${MINGW_PACKAGE_PREFIX}-python-matplotlib: for visualizing DesignSpaceDocument and resulting VariationModel")
fi
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pyfilesystem2"
              "${MINGW_PACKAGE_PREFIX}-python-pytest"
              "${MINGW_PACKAGE_PREFIX}-python-brotli"
              "${MINGW_PACKAGE_PREFIX}-python-ufolib2")
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('6675329885c44657f826ef01d9e4fb33b9158e9d93c537d84ad8399539bc6f69')

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

#Enable tests when the dependencies are solved
check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  PYTHONPATH=Lib ${MINGW_PREFIX}/bin/python -m pytest || warning "Tests failed"
}

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 -D -m755 LICENSE "${pkgdir}${MINGW_PREFIX}"/share/licenses/python-${_realname}/LICENSE
  chmod oga+r "${pkgdir}${MINGW_PREFIX}"/share/man/man1/ttx.1
}
