commit:     228e91ddbbe3bfc44c9504684efe2051dc0562ca
Author:     Petr Vaněk <arkamar <AT> gentoo <DOT> org>
AuthorDate: Mon Jul  1 12:21:07 2024 +0000
Commit:     Petr Vaněk <arkamar <AT> gentoo <DOT> org>
CommitDate: Mon Jul  1 14:08:10 2024 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=228e91dd

dev-python/flatbuffers: test support for Numpy 2.0

Signed-off-by: Petr Vaněk <arkamar <AT> gentoo.org>

 .../files/flatbuffers-24.3.25-numpy-2.patch        | 72 ++++++++++++++++++++++
 .../flatbuffers/flatbuffers-24.3.25-r1.ebuild      | 46 ++++++++++++++
 2 files changed, 118 insertions(+)

diff --git a/dev-python/flatbuffers/files/flatbuffers-24.3.25-numpy-2.patch 
b/dev-python/flatbuffers/files/flatbuffers-24.3.25-numpy-2.patch
new file mode 100644
index 000000000000..cc5846404764
--- /dev/null
+++ b/dev-python/flatbuffers/files/flatbuffers-24.3.25-numpy-2.patch
@@ -0,0 +1,72 @@
+From d053fbd391610e72fff1f8ee02c1222305f15de9 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Petr=20Van=C4=9Bk?= <[email protected]>
+Date: Mon, 1 Jul 2024 10:29:39 +0000
+Subject: [PATCH] Support for Numpy 2.0 in tests
+
+The newbyteorder has been removed in Numpy 2.0 [1]. Its usages are
+replaced with respect to migration guide.
+
+[1] 
https://numpy.org/devdocs/numpy_2_0_migration_guide.html#ndarray-and-scalar-methods
+
+Fixes: #8332
+
+Upstream-PR: https://github.com/google/flatbuffers/pull/8346
+
+diff --git a/tests/py_test.py b/tests/py_test.py
+index 7d6c0a37966..fc13a490f71 100644
+--- a/tests/py_test.py
++++ b/tests/py_test.py
+@@ -1095,7 +1095,7 @@ def test_create_numpy_vector_int8(self):
+ 
+       # Reverse endian:
+       b = flatbuffers.Builder(0)
+-      x_other_endian = x.byteswap().newbyteorder()
++      x_other_endian = x.byteswap().view(x.dtype.newbyteorder())
+       b.CreateNumpyVector(x_other_endian)
+       self.assertBuilderEquals(
+           b,
+@@ -1144,7 +1144,7 @@ def test_create_numpy_vector_uint16(self):
+ 
+       # Reverse endian:
+       b = flatbuffers.Builder(0)
+-      x_other_endian = x.byteswap().newbyteorder()
++      x_other_endian = x.byteswap().view(x.dtype.newbyteorder())
+       b.CreateNumpyVector(x_other_endian)
+       self.assertBuilderEquals(
+           b,
+@@ -1213,7 +1213,7 @@ def test_create_numpy_vector_int64(self):
+ 
+       # Reverse endian:
+       b = flatbuffers.Builder(0)
+-      x_other_endian = x.byteswap().newbyteorder()
++      x_other_endian = x.byteswap().view(x.dtype.newbyteorder())
+       b.CreateNumpyVector(x_other_endian)
+       self.assertBuilderEquals(
+           b,
+@@ -1287,7 +1287,7 @@ def test_create_numpy_vector_float32(self):
+ 
+       # Reverse endian:
+       b = flatbuffers.Builder(0)
+-      x_other_endian = x.byteswap().newbyteorder()
++      x_other_endian = x.byteswap().view(x.dtype.newbyteorder())
+       b.CreateNumpyVector(x_other_endian)
+       self.assertBuilderEquals(
+           b,
+@@ -1361,7 +1361,7 @@ def test_create_numpy_vector_float64(self):
+ 
+       # Reverse endian:
+       b = flatbuffers.Builder(0)
+-      x_other_endian = x.byteswap().newbyteorder()
++      x_other_endian = x.byteswap().view(x.dtype.newbyteorder())
+       b.CreateNumpyVector(x_other_endian)
+       self.assertBuilderEquals(
+           b,
+@@ -1427,7 +1427,7 @@ def test_create_numpy_vector_bool(self):
+ 
+       # Reverse endian:
+       b = flatbuffers.Builder(0)
+-      x_other_endian = x.byteswap().newbyteorder()
++      x_other_endian = x.byteswap().view(x.dtype.newbyteorder())
+       b.CreateNumpyVector(x_other_endian)
+       self.assertBuilderEquals(
+           b,

diff --git a/dev-python/flatbuffers/flatbuffers-24.3.25-r1.ebuild 
b/dev-python/flatbuffers/flatbuffers-24.3.25-r1.ebuild
new file mode 100644
index 000000000000..b14d51c9b1da
--- /dev/null
+++ b/dev-python/flatbuffers/flatbuffers-24.3.25-r1.ebuild
@@ -0,0 +1,46 @@
+# Copyright 1999-2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+DISTUTILS_USE_PEP517=setuptools
+PYTHON_COMPAT=( python3_{10..12} )
+
+inherit distutils-r1
+
+DESCRIPTION="RFC 7049 - Concise Binary Object Representation"
+HOMEPAGE="
+       https://github.com/google/flatbuffers/
+       https://pypi.org/project/flatbuffers/
+"
+SRC_URI="
+       https://github.com/google/${PN}/archive/v${PV}.tar.gz
+               -> ${P}.gh.tar.gz
+"
+S=${WORKDIR}/${P}/python
+
+LICENSE="Apache-2.0"
+SLOT="0"
+KEYWORDS="~amd64 ~arm ~arm64 ~riscv ~sparc ~x86"
+IUSE="test"
+RESTRICT="!test? ( test )"
+
+BDEPEND="
+       test? (
+               dev-python/numpy[${PYTHON_USEDEP}]
+       )
+"
+
+src_prepare() {
+       cd "${WORKDIR}/${P}" || die
+       eapply "${FILESDIR}/${PN}-24.3.25-numpy-2.patch"
+       cd "${S}" || die
+       distutils-r1_src_prepare
+}
+
+python_test() {
+       cd "${WORKDIR}/${P}/tests" || die
+       # zeroes means without benchmarks
+       "${EPYTHON}" py_test.py 0 0 0 0 false || die
+       "${EPYTHON}" py_flexbuffers_test.py -v || die
+}

Reply via email to