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

_realname=pyopengl
_pyname=PyOpenGL
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=3.1.9
pkgrel=2
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')
url='https://mcfletch.github.io/pyopengl/'
msys2_repository_url="https://github.com/mcfletch/pyopengl"
msys2_references=(
  'archlinux: python-opengl'
  'purl: pkg:pypi/pyopengl'
)
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://pypi.org/packages/source/${_pyname::1}/${_pyname}/${_realname}-${pkgver}.tar.gz"
        "pyopengl-egl-open-warning.patch")
sha256sums=('28ebd82c5f4491a418aeca9672dffb3adbe7d33b39eada4548a5b4e8c03f60c8'
            'e3ce7d0e215565ee3dfc8d87e30d1dfc4d1bdefd6a8ae5459413315ff99d6857')

prepare() {
  cd "${srcdir}"/"${_realname}-${pkgver}"
  patch -Np1 -i ../pyopengl-egl-open-warning.patch
}

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "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"
}
