# Maintainer: Antoine Martin <totaam@xpra.org>

_realname=pyopengl
_pyname=PyOpenGL
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=3.1.8
pkgrel=1
pkgdesc="PyOpenGL is the most common cross platform Python binding to OpenGL and related APIs (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: python-opengl'
  'pypi: PyOpenGL'
)
url='https://pyopengl.sourceforge.io/'
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-cc")
# Running the unit tests requires pygame,
# but since those fail unless you have a GPU, this is not enabled:
# checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pygame")
options=(!strip)
source=("https://github.com/mcfletch/pyopengl/archive/refs/tags/release-${pkgver}.tar.gz"
	"pyopengl-egl-open-warning.patch"
	"pyopengl-version.patch"
)
sha256sums=('78f4016f13705d66dc89d5d046eee660c2f5f0915e5ecfeeed79dffac741bc97'
            'e3ce7d0e215565ee3dfc8d87e30d1dfc4d1bdefd6a8ae5459413315ff99d6857'
            '7ac1e898df3de7caa8655b63c0f11a63136f06b16117a264e1aadb0aae5986a9'
)

prepare() {
  cd "${srcdir}"
  rm -rf python-build-${MSYSTEM} | true
  cp -r "pyopengl-release-${pkgver}" "python-build-${MSYSTEM}"
  cd "python-build-${MSYSTEM}"
  patch -Np1 -i ../pyopengl-egl-open-warning.patch
  patch -Np1 -i ../pyopengl-version.patch
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  # The tests fail without a GPU?
  # cd "${srcdir}/python-build-${MSYSTEM}"
  # ${MINGW_PREFIX}/bin/python -m pytest
  true
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  rm -r "${pkgdir}"${MINGW_PREFIX}/lib/python*/site-packages/OpenGL/DLLS

  install -Dm644 license.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/COPYING"
}
