commit:     64ef68f4772f7e53f5d55ec348d35d0f521b3e5b
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Sun Jun  2 14:31:18 2024 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Sun Jun  2 15:43:09 2024 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=64ef68f4

dev-python/pygame: Backport numpy-2 fixes

Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 dev-python/pygame/files/pygame-2.5.2-numpy-2.patch | 135 +++++++++++++++++++++
 dev-python/pygame/pygame-2.5.2-r3.ebuild           | 107 ++++++++++++++++
 2 files changed, 242 insertions(+)

diff --git a/dev-python/pygame/files/pygame-2.5.2-numpy-2.patch 
b/dev-python/pygame/files/pygame-2.5.2-numpy-2.patch
new file mode 100644
index 000000000000..37b702e57280
--- /dev/null
+++ b/dev-python/pygame/files/pygame-2.5.2-numpy-2.patch
@@ -0,0 +1,135 @@
+From 21859cd1b108c2073dfd5fd197714c2b391e3824 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Ren=C3=A9=20Dudfield?= <[email protected]>
+Date: Tue, 21 May 2024 10:24:52 +0200
+Subject: [PATCH 1/3] test: Fix numpy.alltrue imports to import all instead
+ thanks @mgorny
+
+---
+ test/pixelcopy_test.py | 2 +-
+ test/sndarray_test.py  | 2 +-
+ test/surfarray_test.py | 2 +-
+ 3 files changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/test/pixelcopy_test.py b/test/pixelcopy_test.py
+index 6510fd99..46051cd4 100644
+--- a/test/pixelcopy_test.py
++++ b/test/pixelcopy_test.py
+@@ -534,7 +534,7 @@ class PixelCopyTestWithArrayNumpy(unittest.TestCase):
+ 
+     def test_map_array(self):
+         try:
+-            from numpy import array, zeros, uint8, int32, alltrue
++            from numpy import array, zeros, uint8, int32, all as alltrue
+         except ImportError:
+             return
+ 
+diff --git a/test/sndarray_test.py b/test/sndarray_test.py
+index 5b624caf..7a7a51f3 100644
+--- a/test/sndarray_test.py
++++ b/test/sndarray_test.py
+@@ -1,6 +1,6 @@
+ import unittest
+ 
+-from numpy import int8, int16, uint8, uint16, float32, array, alltrue
++from numpy import int8, int16, uint8, uint16, float32, array, all as alltrue
+ 
+ import pygame
+ import pygame.sndarray
+diff --git a/test/surfarray_test.py b/test/surfarray_test.py
+index 0863da77..a9d53fc4 100644
+--- a/test/surfarray_test.py
++++ b/test/surfarray_test.py
+@@ -9,7 +9,7 @@ from numpy import (
+     zeros,
+     float32,
+     float64,
+-    alltrue,
++    all as alltrue,
+     rint,
+     arange,
+ )
+-- 
+2.45.2
+
+From 4a2ede7b8a1e90c77ab90aadd9c26a2757124923 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Ren=C3=A9=20Dudfield?= <[email protected]>
+Date: Sun, 2 Jun 2024 13:15:26 +0200
+Subject: [PATCH 2/3] sndarray_test: Fix some overflowed data sizes
+
+---
+ test/sndarray_test.py | 8 ++++----
+ 1 file changed, 4 insertions(+), 4 deletions(-)
+
+diff --git a/test/sndarray_test.py b/test/sndarray_test.py
+index 7a7a51f3..57eb71c3 100644
+--- a/test/sndarray_test.py
++++ b/test/sndarray_test.py
+@@ -41,7 +41,7 @@ class SndarrayTest(unittest.TestCase):
+             16, 2, [[0, 0xFFFF], [0xFFFF, 0], [0x00FF, 0xFF00], [0x0F0F, 
0xF0F0]]
+         )
+         check_array(-8, 1, [0, -0x80, 0x7F, 0x64])
+-        check_array(-8, 2, [[0, -0x80], [-0x64, 0x64], [0x25, -0x50], [0xFF, 
0]])
++        check_array(-8, 2, [[0, -0x80], [-0x64, 0x64], [0x25, -0x50], [-1, 
0]])
+         check_array(-16, 1, [0, 0x7FFF, -0x7FFF, -1])
+         check_array(-16, 2, [[0, -0x7FFF], [-0x7FFF, 0], [0x7FFF, 0], [0, 
0x7FFF]])
+ 
+@@ -78,13 +78,13 @@ class SndarrayTest(unittest.TestCase):
+                 pygame.mixer.quit()
+ 
+         check_sound(8, 1, [0, 0x0F, 0xF0, 0xFF])
+-        check_sound(8, 2, [[0, 0x80], [0x2D, 0x41], [0x64, 0xA1], [0xFF, 
0x40]])
++        check_sound(8, 2, [[0, 0x80], [0x2D, 0x41], [0x64, 0xA1], [125, 
0x40]])
+         check_sound(16, 1, [0, 0x00FF, 0xFF00, 0xFFFF])
+         check_sound(
+             16, 2, [[0, 0xFFFF], [0xFFFF, 0], [0x00FF, 0xFF00], [0x0F0F, 
0xF0F0]]
+         )
+         check_sound(-8, 1, [0, -0x80, 0x7F, 0x64])
+-        check_sound(-8, 2, [[0, -0x80], [-0x64, 0x64], [0x25, -0x50], [0xFF, 
0]])
++        check_sound(-8, 2, [[0, -0x80], [-0x64, 0x64], [0x25, -0x50], [-1, 
0]])
+         check_sound(-16, 1, [0, 0x7FFF, -0x7FFF, -1])
+         check_sound(-16, 2, [[0, -0x7FFF], [-0x7FFF, 0], [0x7FFF, 0], [0, 
0x7FFF]])
+         check_sound(32, 2, [[0.0, -1.0], [-1.0, 0], [1.0, 0], [0, 1.0]])
+@@ -123,7 +123,7 @@ class SndarrayTest(unittest.TestCase):
+             16, 2, [[0, 0xFFFF], [0xFFFF, 0], [0x00FF, 0xFF00], [0x0F0F, 
0xF0F0]]
+         )
+         check_sample(-8, 1, [0, -0x80, 0x7F, 0x64])
+-        check_sample(-8, 2, [[0, -0x80], [-0x64, 0x64], [0x25, -0x50], [0xFF, 
0]])
++        check_sample(-8, 2, [[0, -0x80], [-0x64, 0x64], [0x25, -0x50], [-1, 
0]])
+         check_sample(-16, 1, [0, 0x7FFF, -0x7FFF, -1])
+         check_sample(-16, 2, [[0, -0x7FFF], [-0x7FFF, 0], [0x7FFF, 0], [0, 
0x7FFF]])
+         check_sample(32, 2, [[0.0, -1.0], [-1.0, 0], [1.0, 0], [0, 1.0]])
+-- 
+2.45.2
+
+From 184f8b78e6952aa619e961553835c442b3db8d5c Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Ren=C3=A9=20Dudfield?= <[email protected]>
+Date: Sun, 2 Jun 2024 13:27:34 +0200
+Subject: [PATCH 3/3] surfarray_test: Fix for value out of uint32 range
+
+Was in signed 32bit range.
+---
+ test/surfarray_test.py | 8 ++++----
+ 1 file changed, 4 insertions(+), 4 deletions(-)
+
+diff --git a/test/surfarray_test.py b/test/surfarray_test.py
+index a9d53fc4..ee74290e 100644
+--- a/test/surfarray_test.py
++++ b/test/surfarray_test.py
+@@ -113,10 +113,10 @@ class SurfarrayModuleTest(unittest.TestCase):
+ 
+     def _fill_array2d(self, arr, surf):
+         palette = self.test_palette
+-        arr[:5, :6] = surf.map_rgb(palette[1])
+-        arr[5:, :6] = surf.map_rgb(palette[2])
+-        arr[:5, 6:] = surf.map_rgb(palette[3])
+-        arr[5:, 6:] = surf.map_rgb(palette[4])
++        arr[:5, :6] = surf.map_rgb(palette[1]) & 0xFFFFFFFF
++        arr[5:, :6] = surf.map_rgb(palette[2]) & 0xFFFFFFFF
++        arr[:5, 6:] = surf.map_rgb(palette[3]) & 0xFFFFFFFF
++        arr[5:, 6:] = surf.map_rgb(palette[4]) & 0xFFFFFFFF
+ 
+     def _fill_array3d(self, arr):
+         palette = self.test_palette
+-- 
+2.45.2
+

diff --git a/dev-python/pygame/pygame-2.5.2-r3.ebuild 
b/dev-python/pygame/pygame-2.5.2-r3.ebuild
new file mode 100644
index 000000000000..5c10b9bc4adc
--- /dev/null
+++ b/dev-python/pygame/pygame-2.5.2-r3.ebuild
@@ -0,0 +1,107 @@
+# 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..12} pypy3 )
+
+inherit distutils-r1
+
+DESCRIPTION="Python bindings for SDL multimedia library"
+HOMEPAGE="
+       https://www.pygame.org/
+       https://github.com/pygame/pygame/
+       https://pypi.org/project/pygame/
+"
+SRC_URI="
+       https://github.com/pygame/pygame/archive/${PV}.tar.gz
+               -> ${P}.gh.tar.gz
+"
+
+LICENSE="LGPL-2.1"
+SLOT="0"
+KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~riscv ~x86"
+IUSE="examples opengl test X"
+RESTRICT="!test? ( test )"
+
+RDEPEND="
+       dev-python/numpy[${PYTHON_USEDEP}]
+       media-libs/freetype
+       media-libs/libjpeg-turbo:=
+       media-libs/libpng:=
+       media-libs/portmidi
+       media-libs/sdl2-image
+       media-libs/sdl2-mixer
+       media-libs/sdl2-ttf
+       X? ( media-libs/libsdl2[opengl?,threads(+),video,X] )
+       !X? ( media-libs/libsdl2[threads(+)] )
+"
+DEPEND="
+       ${RDEPEND}
+       test? (
+               media-libs/sdl2-image[gif,jpeg,png,tiff,webp]
+               media-libs/sdl2-mixer[mp3,vorbis,wav]
+       )
+"
+# fontconfig used for fc-list
+RDEPEND+="
+       media-libs/fontconfig
+"
+# util-linux provides script
+BDEPEND="
+       dev-python/cython[${PYTHON_USEDEP}]
+       test? (
+               media-libs/fontconfig
+               sys-apps/util-linux
+       )
+"
+
+src_prepare() {
+       local PATCHES=(
+               # https://github.com/pygame/pygame/pull/4035
+               "${FILESDIR}/${P}-error.patch"
+               # https://github.com/pygame/pygame/pull/4236
+               "${FILESDIR}/${P}-gcc-14.patch"
+               # https://github.com/pygame/pygame/pull/4240
+               # https://github.com/pygame/pygame/pull/4254
+               # https://github.com/pygame/pygame/pull/4255
+               "${FILESDIR}/${P}-numpy-2.patch"
+       )
+
+       # some numpy-related crash (not a regression)
+       # https://github.com/pygame/pygame/issues/4049
+       sed -e 's:import numpy:raise ImportError(""):' \
+               -i test/pixelcopy_test.py || die
+
+       distutils-r1_src_prepare
+}
+
+python_configure() {
+       PORTMIDI_INC_PORTTIME=1 LOCALBASE="${EPREFIX}/usr" \
+               "${EPYTHON}" "${S}"/buildconfig/config.py || die
+}
+
+python_configure_all() {
+       find src_c/cython -name '*.pyx' -exec touch {} + || die
+       "${EPYTHON}" setup.py cython_only || die
+}
+
+python_test() {
+       local -x SDL_VIDEODRIVER=dummy
+       local -x SDL_AUDIODRIVER=disk
+       script -eqc "${EPYTHON} -m pygame.tests -v" || die
+}
+
+python_install() {
+       distutils-r1_python_install
+
+       # https://bugs.gentoo.org/497720
+       rm -fr "${D}$(python_get_sitedir)"/pygame/{docs,examples} || die
+}
+
+python_install_all() {
+       distutils-r1_python_install_all
+       use examples && dodoc -r examples
+}

Reply via email to