commit:     595fed557b00b2cb13c5f7d20a95706128245142
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Mon Feb 24 10:39:57 2025 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Mon Feb 24 12:30:52 2025 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=595fed55

dev-python/zstandard: Patch for zstd-1.5.7 support

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

 .../files/zstandard-0.23.0-zstd-1.5.7.patch        | 163 +++++++++++++++++++++
 dev-python/zstandard/zstandard-0.23.0-r2.ebuild    |  81 ++++++++++
 2 files changed, 244 insertions(+)

diff --git a/dev-python/zstandard/files/zstandard-0.23.0-zstd-1.5.7.patch 
b/dev-python/zstandard/files/zstandard-0.23.0-zstd-1.5.7.patch
new file mode 100644
index 000000000000..c9d1c1d8690d
--- /dev/null
+++ b/dev-python/zstandard/files/zstandard-0.23.0-zstd-1.5.7.patch
@@ -0,0 +1,163 @@
+From 33c483f2df0be8de9df847c7cdfa9f9b32afc7aa Mon Sep 17 00:00:00 2001
+From: "Bernhard M. Wiedemann" <[email protected]>
+Date: Fri, 21 Feb 2025 20:59:18 +0100
+Subject: [PATCH 1/3] Use zstd-1.5.7
+
+this changed compression results, so we have to adapt tests
+---
+ c-ext/backend_c.c                      | 2 +-
+ tests/test_compressor_compress.py      | 2 +-
+ tests/test_compressor_compressobj.py   | 2 +-
+ tests/test_compressor_copy_stream.py   | 2 +-
+ tests/test_compressor_stream_writer.py | 2 +-
+ tests/test_module_attributes.py        | 2 +-
+ 6 files changed, 6 insertions(+), 6 deletions(-)
+
+diff --git a/c-ext/backend_c.c b/c-ext/backend_c.c
+index aabe30b..4b09d1f 100644
+--- a/c-ext/backend_c.c
++++ b/c-ext/backend_c.c
+@@ -152,7 +152,7 @@ void zstd_module_init(PyObject *m) {
+     PyObject *features = NULL;
+     PyObject *feature = NULL;
+     unsigned zstd_ver_no = ZSTD_versionNumber();
+-    unsigned our_hardcoded_version = 10506;
++    unsigned our_hardcoded_version = 10507;
+     if (ZSTD_VERSION_NUMBER != our_hardcoded_version ||
+         zstd_ver_no != our_hardcoded_version) {
+         PyErr_Format(
+diff --git a/tests/test_compressor_compress.py 
b/tests/test_compressor_compress.py
+index d96d476..c978c19 100644
+--- a/tests/test_compressor_compress.py
++++ b/tests/test_compressor_compress.py
+@@ -52,7 +52,7 @@ class TestCompressor_compress(unittest.TestCase):
+ 
+         cctx = zstd.ZstdCompressor(level=3, write_content_size=False)
+         result = cctx.compress(b"".join(chunks))
+-        self.assertEqual(len(result), 999)
++        self.assertEqual(len(result), 1029)
+         self.assertEqual(result[0:4], b"\x28\xb5\x2f\xfd")
+ 
+         # This matches the test for read_to_iter() below.
+diff --git a/tests/test_compressor_compressobj.py 
b/tests/test_compressor_compressobj.py
+index f429b32..b89ae20 100644
+--- a/tests/test_compressor_compressobj.py
++++ b/tests/test_compressor_compressobj.py
+@@ -39,7 +39,7 @@ class TestCompressor_compressobj(unittest.TestCase):
+         cobj = cctx.compressobj()
+ 
+         result = cobj.compress(b"".join(chunks)) + cobj.flush()
+-        self.assertEqual(len(result), 999)
++        self.assertEqual(len(result), 1029)
+         self.assertEqual(result[0:4], b"\x28\xb5\x2f\xfd")
+ 
+         params = zstd.get_frame_parameters(result)
+diff --git a/tests/test_compressor_copy_stream.py 
b/tests/test_compressor_copy_stream.py
+index 82c7ce7..685660f 100644
+--- a/tests/test_compressor_copy_stream.py
++++ b/tests/test_compressor_copy_stream.py
+@@ -50,7 +50,7 @@ class TestCompressor_copy_stream(unittest.TestCase):
+         r, w = cctx.copy_stream(source, dest)
+ 
+         self.assertEqual(r, 255 * 16384)
+-        self.assertEqual(w, 999)
++        self.assertEqual(w, 1029)
+ 
+         params = zstd.get_frame_parameters(dest.getvalue())
+         self.assertEqual(params.content_size, zstd.CONTENTSIZE_UNKNOWN)
+diff --git a/tests/test_compressor_stream_writer.py 
b/tests/test_compressor_stream_writer.py
+index cfa198b..3baa788 100644
+--- a/tests/test_compressor_stream_writer.py
++++ b/tests/test_compressor_stream_writer.py
+@@ -301,7 +301,7 @@ class TestCompressor_stream_writer(unittest.TestCase):
+         d = zstd.train_dictionary(8192, samples)
+ 
+         h = hashlib.sha1(d.as_bytes()).hexdigest()
+-        self.assertEqual(h, "a46d2f7a3bc3357c9d717d3dadf9a26fde23e93d")
++        self.assertEqual(h, "f32ddfbe0878bbd428afc00b17810387c6752191")
+ 
+         buffer = io.BytesIO()
+         cctx = zstd.ZstdCompressor(level=9, dict_data=d)
+diff --git a/tests/test_module_attributes.py b/tests/test_module_attributes.py
+index a99ed2e..3e3b482 100644
+--- a/tests/test_module_attributes.py
++++ b/tests/test_module_attributes.py
+@@ -5,7 +5,7 @@ import zstandard as zstd
+ 
+ class TestModuleAttributes(unittest.TestCase):
+     def test_version(self):
+-        self.assertEqual(zstd.ZSTD_VERSION, (1, 5, 6))
++        self.assertEqual(zstd.ZSTD_VERSION, (1, 5, 7))
+ 
+         self.assertEqual(zstd.__version__, "0.23.0")
+ 
+From f598b951f36b6259fd7871892dd1e136f96c58ec Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <[email protected]>
+Date: Mon, 24 Feb 2025 11:30:29 +0100
+Subject: [PATCH 2/3] Update make_cffi.py to skip type alias macros in zstd
+ 1.5.7
+
+---
+ make_cffi.py | 9 +++++++--
+ 1 file changed, 7 insertions(+), 2 deletions(-)
+
+diff --git a/make_cffi.py b/make_cffi.py
+index 170d1e5..763abb2 100644
+--- a/make_cffi.py
++++ b/make_cffi.py
+@@ -179,7 +179,7 @@ ffi.set_source(
+     include_dirs=INCLUDE_DIRS,
+ )
+ 
+-DEFINE = re.compile(b"^\\#define ([a-zA-Z0-9_]+) ")
++DEFINE = re.compile(rb"^#define\s+([a-zA-Z0-9_]+)\s+(\S+)")
+ 
+ sources = []
+ 
+@@ -204,9 +204,14 @@ for header in HEADERS:
+             if m.group(1) in (b"ZSTD_LIB_VERSION", b"ZSTD_VERSION_STRING"):
+                 continue
+ 
++            # These defines create aliases from old (camelCase) type names
++            # to the new PascalCase names, which breaks CFFI.
++            if m.group(1).lower() == m.group(2).lower():
++                continue
++
+             # The ... is magic syntax by the cdef parser to resolve the
+             # value at compile time.
+-            sources.append(m.group(0) + b" ...")
++            sources.append(b"#define " + m.group(1) + b" ...")
+ 
+ cdeflines = b"\n".join(sources).splitlines()
+ cdeflines = [l for l in cdeflines if l.strip()]
+From fb56d2b5ab38132bff998b15a0d3de4e91569167 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <[email protected]>
+Date: Mon, 24 Feb 2025 11:30:46 +0100
+Subject: [PATCH 3/3] Update backend_cffi for new type names in zstd 1.5.7
+
+---
+ zstandard/backend_cffi.py | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/zstandard/backend_cffi.py b/zstandard/backend_cffi.py
+index 80d6fc8..38427f4 100644
+--- a/zstandard/backend_cffi.py
++++ b/zstandard/backend_cffi.py
+@@ -2574,7 +2574,7 @@ def get_frame_parameters(data):
+     :return:
+        :py:class:`FrameParameters`
+     """
+-    params = ffi.new("ZSTD_frameHeader *")
++    params = ffi.new("ZSTD_FrameHeader *")
+ 
+     data_buffer = ffi.from_buffer(data)
+     zresult = lib.ZSTD_getFrameHeader(params, data_buffer, len(data_buffer))
+@@ -4289,7 +4289,7 @@ class ZstdDecompressor(object):
+ 
+         # All chunks should be zstd frames and should have content size set.
+         chunk_buffer = ffi.from_buffer(chunk)
+-        params = ffi.new("ZSTD_frameHeader *")
++        params = ffi.new("ZSTD_FrameHeader *")
+         zresult = lib.ZSTD_getFrameHeader(
+             params, chunk_buffer, len(chunk_buffer)
+         )

diff --git a/dev-python/zstandard/zstandard-0.23.0-r2.ebuild 
b/dev-python/zstandard/zstandard-0.23.0-r2.ebuild
new file mode 100644
index 000000000000..b82bca58b70b
--- /dev/null
+++ b/dev-python/zstandard/zstandard-0.23.0-r2.ebuild
@@ -0,0 +1,81 @@
+# Copyright 1999-2025 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} pypy3 pypy3_11 )
+
+inherit distutils-r1
+
+MY_P=python-zstandard-${PV}
+DESCRIPTION="Zstandard Bindings for Python"
+HOMEPAGE="
+       https://github.com/indygreg/python-zstandard/
+       https://pypi.org/project/zstandard/
+"
+SRC_URI="
+       https://github.com/indygreg/python-zstandard/archive/${PV}.tar.gz
+               -> ${MY_P}.gh.tar.gz
+"
+S=${WORKDIR}/${MY_P}
+
+LICENSE="BSD"
+SLOT="0"
+KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~loong ~m68k ~mips ~ppc ~ppc64 
~riscv ~s390 ~sparc ~x86 ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos 
~x64-solaris"
+
+DEPEND="
+       >=app-arch/zstd-1.5.7:=
+"
+RDEPEND="
+       ${DEPEND}
+       $(python_gen_cond_dep '
+               >=dev-python/cffi-1.14.0-r2:=[${PYTHON_USEDEP}]
+       ' 'python*')
+"
+BDEPEND="
+       test? (
+               dev-python/hypothesis[${PYTHON_USEDEP}]
+       )
+"
+
+distutils_enable_tests pytest
+
+src_prepare() {
+       local PATCHES=(
+               # https://github.com/indygreg/python-zstandard/pull/255
+               "${FILESDIR}/${P}-zstd-1.5.7.patch"
+       )
+
+       # the C backend is repeatedly broken, so force CFFI instead
+       sed -e '/PYTHON_ZSTANDARD_IMPORT_POLICY/s:default:cffi:' \
+               -i zstandard/__init__.py || die
+       # unbundle zstd
+       rm zstd/* || die
+       > zstd/zstd.c || die
+       # it does random preprocessing on that, so we can't use #include
+       local f
+       for f in zdict.h zstd.h; do
+               cp "${ESYSROOT}/usr/include/${f}" "zstd/${f}" || die
+       done
+       sed -i -e '/include_dirs/a    libraries=["zstd"],' make_cffi.py || die
+
+       distutils-r1_src_prepare
+
+       DISTUTILS_ARGS=(
+               --no-c-backend
+       )
+}
+
+python_test() {
+       local EPYTEST_DESELECT=(
+               # unreliable, fails on x86
+               
tests/test_data_structures.py::TestCompressionParameters::test_estimated_compression_context_size
+               # check for bundled zstd version, fails on other system zstd
+               
tests/test_module_attributes.py::TestModuleAttributes::test_version
+       )
+
+       rm -rf zstandard || die
+       epytest
+}

Reply via email to