commit: d55e65d3b06c147bff169cd6704e45ebf82d860c Author: Paul Zander <negril.nx+gentoo <AT> gmail <DOT> com> AuthorDate: Sun Oct 6 16:38:32 2024 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Sun Dec 1 12:16:58 2024 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=d55e65d3
dev-python/pyopengl-accelerate: add 3.1.8-r1, 9999, update for numpy-2.0 Signed-off-by: Paul Zander <negril.nx+gentoo <AT> gmail.com> Closes: https://github.com/gentoo/gentoo/pull/37232 Signed-off-by: Sam James <sam <AT> gentoo.org> .../files/pyopengl-accelerate-3.1.8-gcc-14.patch | 42 +++++ .../pyopengl-accelerate-3.1.8-numpy-2.0.patch | 171 +++++++++++++++++++++ .../pyopengl-accelerate-3.1.8-r1.ebuild | 81 ++++++++++ .../pyopengl-accelerate-9999.ebuild | 81 ++++++++++ 4 files changed, 375 insertions(+) diff --git a/dev-python/pyopengl-accelerate/files/pyopengl-accelerate-3.1.8-gcc-14.patch b/dev-python/pyopengl-accelerate/files/pyopengl-accelerate-3.1.8-gcc-14.patch new file mode 100644 index 000000000000..56f976288316 --- /dev/null +++ b/dev-python/pyopengl-accelerate/files/pyopengl-accelerate-3.1.8-gcc-14.patch @@ -0,0 +1,42 @@ +From fbe0fab7947788039cb4fbc9a5a1ea65a0c0e15b Mon Sep 17 00:00:00 2001 +From: Florian Weimer <[email protected]> +Date: Fri, 5 Jan 2024 08:48:12 +0100 +Subject: [PATCH 1/2] accelerate: Fix type of PyArray_FillWithScalar + +The first argument is of type PyArrayObject, not PyObject. +--- a/accelerate/src/numpy_formathandler.pyx ++++ b/accelerate/src/numpy_formathandler.pyx +@@ -22,7 +22,7 @@ cdef extern from "numpy/arrayobject.h": + int PyArray_ISCARRAY_RO( np.ndarray instance ) + cdef np.ndarray PyArray_Zeros(int nd, np.npy_intp* dims, np.dtype, int fortran) + cdef np.ndarray PyArray_EnsureArray(object) +- cdef int PyArray_FillWithScalar(object, object) ++ cdef int PyArray_FillWithScalar(np.ndarray, object) + cdef void import_array() + cdef void* PyArray_DATA( np.ndarray ) + cdef int PyArray_NDIM( np.ndarray ) + +From f62dd58a5437c628d3ff3e626d4507811ef2127b Mon Sep 17 00:00:00 2001 +From: Florian Weimer <[email protected]> +Date: Fri, 5 Jan 2024 08:48:43 +0100 +Subject: [PATCH 2/2] accelerate: Use recommended way to integrate NumPy with + Cython + +This approach follows +<https://cython.readthedocs.io/en/latest/src/tutorial/numpy.html#adding-types>. +--- a/accelerate/src/numpy_formathandler.pyx ++++ b/accelerate/src/numpy_formathandler.pyx +@@ -23,7 +23,6 @@ cdef extern from "numpy/arrayobject.h": + cdef np.ndarray PyArray_Zeros(int nd, np.npy_intp* dims, np.dtype, int fortran) + cdef np.ndarray PyArray_EnsureArray(object) + cdef int PyArray_FillWithScalar(np.ndarray, object) +- cdef void import_array() + cdef void* PyArray_DATA( np.ndarray ) + cdef int PyArray_NDIM( np.ndarray ) + cdef int *PyArray_DIMS( np.ndarray ) +@@ -227,4 +226,4 @@ cdef class NumpyHandler(FormatHandler): + + # Cython numpy tutorial neglects to mention this AFAICS + # get segfaults without it +-import_array() ++np.import_array() diff --git a/dev-python/pyopengl-accelerate/files/pyopengl-accelerate-3.1.8-numpy-2.0.patch b/dev-python/pyopengl-accelerate/files/pyopengl-accelerate-3.1.8-numpy-2.0.patch new file mode 100644 index 000000000000..a7d1c50db4ed --- /dev/null +++ b/dev-python/pyopengl-accelerate/files/pyopengl-accelerate-3.1.8-numpy-2.0.patch @@ -0,0 +1,171 @@ +From 20213b913f4a396752c515cafd7ee2ea53ab1fcf Mon Sep 17 00:00:00 2001 +From: Paul Zander <[email protected]> +Date: Thu, 20 Jun 2024 17:03:20 +0200 +Subject: [PATCH 1/2] add requirements + +Signed-off-by: Paul Zander <[email protected]> +--- a/requirements.txt ++++ b/requirements.txt +@@ -0,0 +1,4 @@ ++numpy>=2.0.0 ++pytest>=8.2.2 ++setuptools>=70.0.0 ++Cython>=3.0.10 +\ No newline at end of file +-- +2.45.2 + + +From bfb5c7005917fc5b4cb71e17b2ed8cc015828f1b Mon Sep 17 00:00:00 2001 +From: Paul Zander <[email protected]> +Date: Thu, 20 Jun 2024 21:40:28 +0200 +Subject: [PATCH 1/5] numpy-2.0 define_macros + +Signed-off-by: Paul Zander <[email protected]> +--- a/setup.py ++++ b/setup.py +@@ -45,7 +45,7 @@ def cython_extension( + # *cython* itself is using the deprecated api, and the + # deprecated APIs are actually providing the attributes + # that we use throughout our code... +- # ('NPY_NO_DEPRECATED_API','NPY_1_7_API_VERSION'), ++ ('NPY_NO_DEPRECATED_API', 'NPY_2_0_API_VERSION'), + ], + compiler_directives={'language_level': "3"} if have_cython else {}, + ) +-- +2.45.2 + + +From b352289a51b2629917b59ee2b35569651436af70 Mon Sep 17 00:00:00 2001 +From: Paul Zander <[email protected]> +Date: Thu, 20 Jun 2024 21:42:33 +0200 +Subject: [PATCH 2/5] python-3.11-PyMemoryView_GetContiguous + +Signed-off-by: Paul Zander <[email protected]> +--- a/src/buffers_formathandler.pyx ++++ b/src/buffers_formathandler.pyx +@@ -73,8 +73,8 @@ cdef class MemoryviewHandler(FormatHandler): + # TODO: respect no-copy flag! + instance = PyMemoryView_GetContiguous( + instance, +- PyBUF_STRIDES|PyBUF_FORMAT|PyBUF_C_CONTIGUOUS, + 'C' ++ PyBUF_WRITE, + ) + return instance + cdef c_from_param( self, object instance, object typeCode ): +-- +2.45.2 + + +From 86268a423c994f0808bd745ac4b0dfe69c8682ad Mon Sep 17 00:00:00 2001 +From: Paul Zander <[email protected]> +Date: Thu, 20 Jun 2024 21:43:32 +0200 +Subject: [PATCH 3/5] enable conversion to C char + +Signed-off-by: Paul Zander <[email protected]> +--- a/src/buffers_formathandler.pyx ++++ b/src/buffers_formathandler.pyx +@@ -73,8 +73,8 @@ cdef class MemoryviewHandler(FormatHandler): + # TODO: respect no-copy flag! + instance = PyMemoryView_GetContiguous( + instance, +- 'C' + PyBUF_WRITE, ++ b'C' + ) + return instance + cdef c_from_param( self, object instance, object typeCode ): +-- +2.45.2 + + +From 8d8618cd4d318ace3ecabe823da0dcfdae2fb0e5 Mon Sep 17 00:00:00 2001 +From: Paul Zander <[email protected]> +Date: Thu, 20 Jun 2024 21:44:53 +0200 +Subject: [PATCH 4/5] set language_level + +Signed-off-by: Paul Zander <[email protected]> +--- a/setup.py ++++ b/setup.py +@@ -47,7 +47,6 @@ def cython_extension( + # that we use throughout our code... + ('NPY_NO_DEPRECATED_API', 'NPY_2_0_API_VERSION'), + ], +- compiler_directives={'language_level': "3"} if have_cython else {}, + ) + + +@@ -116,6 +115,8 @@ if ( # Prevents running of setup during code introspection imports + extraArguments["cmdclass"] = { + "build_ext": build_ext, + } ++ for e in extensions: ++ e.cython_directives = {'language_level': "3"} + setup( + options={ + "sdist": { +--- a/src/numpy_formathandler.pyx ++++ b/src/numpy_formathandler.pyx +@@ -1,5 +1,5 @@ + """Accelerator for numpy format handler operations""" +-#cython: language_level=3 ++# cython: language_level=3 + from ctypes import c_void_p + import numpy as np + cimport numpy as np +-- +2.45.2 + + +From 6cd6e7c053e3268086e90df6d1297941cbce93f2 Mon Sep 17 00:00:00 2001 +From: Paul Zander <[email protected]> +Date: Thu, 20 Jun 2024 21:46:46 +0200 +Subject: [PATCH 5/5] drop old cython numpy definitions + +Signed-off-by: Paul Zander <[email protected]> +--- a/src/numpy_formathandler.pyx ++++ b/src/numpy_formathandler.pyx +@@ -3,36 +3,18 @@ + from ctypes import c_void_p + import numpy as np + cimport numpy as np ++from numpy cimport * + from OpenGL_accelerate.formathandler cimport FormatHandler +-import traceback, weakref + from OpenGL.error import CopyError + from OpenGL._bytes import bytes,unicode + +-cdef extern from "Python.h": +- cdef void Py_INCREF( object ) +- + cdef extern from "numpy/arrayobject.h": + cdef np.ndarray PyArray_FromArray( np.ndarray, np.dtype, int ) +- cdef np.ndarray PyArray_ContiguousFromAny( object op, int, int, int max_depth) +- cdef int PyArray_Check( object ) +- cdef int PyArray_CheckScalar( object ) +- int NPY_ARRAY_CARRAY +- int NPY_ARRAY_FORCECAST +- int PyArray_ISCARRAY( np.ndarray instance ) +- int PyArray_ISCARRAY_RO( np.ndarray instance ) + cdef np.ndarray PyArray_Zeros(int nd, np.npy_intp* dims, np.dtype, int fortran) +- cdef np.ndarray PyArray_EnsureArray(object) +- cdef int PyArray_FillWithScalar(np.ndarray, object) +- cdef void* PyArray_DATA( np.ndarray ) +- cdef int PyArray_NDIM( np.ndarray ) +- cdef int *PyArray_DIMS( np.ndarray ) +- cdef int PyArray_DIM( np.ndarray, int dim ) +- cdef np.dtype PyArray_DESCR( np.ndarray ) +- cdef np.npy_intp PyArray_SIZE( np.ndarray ) + + cdef np.dtype array_descr( np.ndarray array ): + """Wrap PyArray_DESCR and incref to deal with the "borrowed" reference""" +- cdef np.dtype desc = PyArray_DESCR( array ) ++ cdef np.dtype desc = array.dtype + Py_INCREF(<object> desc) + return desc + +-- +2.45.2 + diff --git a/dev-python/pyopengl-accelerate/pyopengl-accelerate-3.1.8-r1.ebuild b/dev-python/pyopengl-accelerate/pyopengl-accelerate-3.1.8-r1.ebuild new file mode 100644 index 000000000000..a2b0f657fce8 --- /dev/null +++ b/dev-python/pyopengl-accelerate/pyopengl-accelerate-3.1.8-r1.ebuild @@ -0,0 +1,81 @@ +# Copyright 1999-2024 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 + +DISTUTILS_EXT=1 +DISTUTILS_USE_PEP517=setuptools +PYTHON_COMPAT=( python3_{10..13} ) + +inherit distutils-r1 + +DESCRIPTION="Accelerate module for PyOpenGL" +HOMEPAGE=" + https://pyopengl.sourceforge.net/ + https://github.com/mcfletch/pyopengl/ + https://pypi.org/project/PyOpenGL-accelerate/ +" + +if [[ ${PV} = *9999* ]] ; then + inherit git-r3 + EGIT_REPO_URI="https://github.com/mcfletch/pyopengl.git" + S="${S}/accelerate" +else + MY_P=pyopengl-release-${PV} + SRC_URI=" + https://github.com/mcfletch/pyopengl/archive/release-${PV}.tar.gz + -> ${MY_P}.gh.tar.gz + " + KEYWORDS="~amd64 ~x86 ~amd64-linux ~x86-linux" + S=${WORKDIR}/${MY_P}/accelerate +fi + +LICENSE="BSD" +SLOT="0" +IUSE="numpy" + +DEPEND=" + numpy? ( + dev-python/numpy:=[${PYTHON_USEDEP}] + ) +" +RDEPEND=" + ${DEPEND} + dev-python/pyopengl[${PYTHON_USEDEP}] +" +BDEPEND=" + dev-python/cython[${PYTHON_USEDEP}] +" + +distutils_enable_tests pytest + +src_prepare() { + default + + touch requirements.txt || die + + eapply -p2 "${FILESDIR}/${PN}-3.1.8-gcc-14.patch" + + eapply -p1 "${FILESDIR}/${PN}-3.1.8-numpy-2.0.patch" +} + +src_configure() { + rm src/*.c || die + + if ! use numpy; then + cat > "${T}"/numpy.py <<-EOF || die + raise ImportError("building numpy extension disabled") + EOF + fi +} + +python_compile() { + local -x PYTHONPATH=${T}:${PYTHONPATH} + distutils-r1_python_compile +} + +python_test() { + local -x PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 + cd "${T}" || die + epytest "${S}"/tests +} diff --git a/dev-python/pyopengl-accelerate/pyopengl-accelerate-9999.ebuild b/dev-python/pyopengl-accelerate/pyopengl-accelerate-9999.ebuild new file mode 100644 index 000000000000..a2b0f657fce8 --- /dev/null +++ b/dev-python/pyopengl-accelerate/pyopengl-accelerate-9999.ebuild @@ -0,0 +1,81 @@ +# Copyright 1999-2024 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 + +DISTUTILS_EXT=1 +DISTUTILS_USE_PEP517=setuptools +PYTHON_COMPAT=( python3_{10..13} ) + +inherit distutils-r1 + +DESCRIPTION="Accelerate module for PyOpenGL" +HOMEPAGE=" + https://pyopengl.sourceforge.net/ + https://github.com/mcfletch/pyopengl/ + https://pypi.org/project/PyOpenGL-accelerate/ +" + +if [[ ${PV} = *9999* ]] ; then + inherit git-r3 + EGIT_REPO_URI="https://github.com/mcfletch/pyopengl.git" + S="${S}/accelerate" +else + MY_P=pyopengl-release-${PV} + SRC_URI=" + https://github.com/mcfletch/pyopengl/archive/release-${PV}.tar.gz + -> ${MY_P}.gh.tar.gz + " + KEYWORDS="~amd64 ~x86 ~amd64-linux ~x86-linux" + S=${WORKDIR}/${MY_P}/accelerate +fi + +LICENSE="BSD" +SLOT="0" +IUSE="numpy" + +DEPEND=" + numpy? ( + dev-python/numpy:=[${PYTHON_USEDEP}] + ) +" +RDEPEND=" + ${DEPEND} + dev-python/pyopengl[${PYTHON_USEDEP}] +" +BDEPEND=" + dev-python/cython[${PYTHON_USEDEP}] +" + +distutils_enable_tests pytest + +src_prepare() { + default + + touch requirements.txt || die + + eapply -p2 "${FILESDIR}/${PN}-3.1.8-gcc-14.patch" + + eapply -p1 "${FILESDIR}/${PN}-3.1.8-numpy-2.0.patch" +} + +src_configure() { + rm src/*.c || die + + if ! use numpy; then + cat > "${T}"/numpy.py <<-EOF || die + raise ImportError("building numpy extension disabled") + EOF + fi +} + +python_compile() { + local -x PYTHONPATH=${T}:${PYTHONPATH} + distutils-r1_python_compile +} + +python_test() { + local -x PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 + cd "${T}" || die + epytest "${S}"/tests +}
