# Maintainer: Filipe Laíns (FFY00) <lains@archlinux.org>
# Maintainer: Morten Linderud <foxboron@archlinux.org>
# Contributor: Eric Bélanger <eric@archlinux.org>

pkgname=python-wxpython
_pkgname=wxPython
pkgver=4.2.4
_pkgver="${pkgver%.*}"
_post="${pkgver##*.}"
pkgrel=1
epoch=1
pkgdesc='Cross-platform GUI toolkit'
arch=('x86_64' 'aarch64')
license=('custom:wxWindows')
url='https://www.wxpython.org'
depends=('wxwidgets-gtk3' 'python')
optdepends=('python-pypubsub: Alternative to the deprecated wx.lib.pubsub API')
makedepends=('mesa' 'glu' 'webkit2gtk-4.1' 'python-requests' 'python-setuptools' 'python-attrdict' 'sip' 'doxygen' 'waf' 'cython')
checkdepends=('xorg-server-xvfb' 'python-pytest-forked' 'python-numpy')
source=("https://files.pythonhosted.org/packages/source/w/wxPython/wxpython-$pkgver.tar.gz")
sha512sums=('4ae124bced8a0d357a34763c981ef370b7c0c978dfba0f941f37e83227816881fee2e65eb7eaa2a114bbaded14afd8e96ad17dba5a9886b38ac35bc75ec82737')

build() {
  cd $_pkgname-$pkgver

#  rm -r sip/{cpp,gen}/* # Recreate sip files with current wxWidgets - broken with doxygen 1.9.7 https://github.com/wxWidgets/Phoenix/issues/2414
  SIP=/usr/bin/sip DOXYGEN=/usr/bin/doxygen WAF=/usr/bin/waf \
  python build.py --nodoc sip build --use_syswx --release
}

check() {
  cd $_pkgname-$pkgver

  # there are segfaulting tests so --forked ensures we get sensible results
  PYTHONPATH=$PWD xvfb-run pytest --forked unittests || echo "==> WARNING: tests usually fail randomly"
}

package() {
  cd $_pkgname-$pkgver

  python build.py install --destdir="$pkgdir"

  install -Dm 644 LICENSE.txt "$pkgdir"/usr/share/licenses/$pkgname/LICENSE.txt
  find "$pkgdir/usr/lib" -type f | xargs chmod 644
}
