Building with --system-zstd still rebuilds the zstd library
For example, the file huf_decompress.c is compiled.
Version 0.9.1
Could you please provide more details about this?
Steps to reproduce, the command line used, and its output, would help in debugging this.
Currently, it fails die to this: https://github.com/indygreg/python-zstandard/issues/52 I will be able to provide more info once this is fixed.
I suspect the OP means the cffi module that doesn't respect system-zstd.
still dont really work with system zstd
[ 42s] =================================== FAILURES ===================================
[ 42s] __________________ TestCompressor_compress.test_multithreaded __________________
[ 42s]
[ 42s] self = <tests.test_compressor.TestCompressor_compress testMethod=test_multithreaded>
[ 42s]
[ 42s] def test_multithreaded(self):
[ 42s] > chunk_size = multithreaded_chunk_size(1)
[ 42s]
[ 42s] tests/test_compressor.py:194:
[ 42s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
[ 42s]
[ 42s] level = 1, source_size = 0
[ 42s]
[ 42s] def multithreaded_chunk_size(level, source_size=0):
[ 42s] > params = zstd.ZstdCompressionParameters.from_level(level, source_size=source_size)
[ 42s] E SystemError: error return without exception set
[ 42s]
[ 42s] tests/test_compressor.py:27: SystemError
[ 42s] _______________ TestCompressor_compress.test_multithreaded_cffi ________________
[ 42s]
[ 42s] self = <tests.test_compressor.TestCompressor_compress testMethod=test_multithreaded_cffi>
[ 42s]
[ 42s] def test_multithreaded(self):
[ 42s] > chunk_size = multithreaded_chunk_size(1)
[ 42s]
[ 42s] tests/test_compressor.py:194:
[ 42s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
[ 42s]
[ 42s] level = 1, source_size = 0
[ 42s]
[ 42s] def multithreaded_chunk_size(level, source_size=0):
[ 42s] > params = zstd.ZstdCompressionParameters.from_level(level, source_size=source_size)
[ 42s] E SystemError: error return without exception set
[ 42s]
[ 42s] tests/test_compressor.py:27: SystemError
[ 42s] ________ TestCompressor_compress.test_multithreaded_compression_params _________
[ 42s]
[ 42s] self = <tests.test_compressor.TestCompressor_compress testMethod=test_multithreaded_compression_params>
[ 42s]
[ 42s] def test_multithreaded_compression_params(self):
[ 42s] > params = zstd.ZstdCompressionParameters.from_level(0, threads=2)
[ 42s] E SystemError: error return without exception set
[ 42s]
[ 42s] tests/test_compressor.py:230: SystemError
[ 42s] _______________ TestCompressor_compress.test_multithreaded_dict ________________
[ 42s]
[ 42s] self = <tests.test_compressor.TestCompressor_compress testMethod=test_multithreaded_dict>
[ 42s]
[ 42s] def test_multithreaded_dict(self):
[ 42s] samples = []
[ 42s] for i in range(128):
[ 42s] samples.append(b"foo" * 64)
[ 42s] samples.append(b"bar" * 64)
[ 42s] samples.append(b"foobar" * 64)
[ 42s]
[ 42s] d = zstd.train_dictionary(1024, samples)
[ 42s]
[ 42s] > cctx = zstd.ZstdCompressor(dict_data=d, threads=2)
[ 42s] E ZstdError: unable to set compression context parameter: Unsupported parameter
[ 42s]
[ 42s] tests/test_compressor.py:217: ZstdError
[ 42s] ____________________ TestCompressor_compress.test_no_magic _____________________
[ 42s]
[ 42s] self = <tests.test_compressor.TestCompressor_compress testMethod=test_no_magic>
[ 42s]
[ 42s] def test_no_magic(self):
[ 42s] > params = zstd.ZstdCompressionParameters.from_level(1, format=zstd.FORMAT_ZSTD1)
[ 42s] E SystemError: error return without exception set
[ 42s]
[ 42s] tests/test_compressor.py:102: SystemError
[ 42s] ________________ TestCompressor_compressobj.test_multithreaded _________________
[ 42s]
[ 42s] self = <tests.test_compressor.TestCompressor_compressobj testMethod=test_multithreaded>
[ 42s]
[ 42s] def test_multithreaded(self):
[ 42s] source = io.BytesIO()
[ 42s] source.write(b"a" * 1048576)
[ 42s] source.write(b"b" * 1048576)
[ 42s] source.write(b"c" * 1048576)
[ 42s] source.seek(0)
[ 42s]
[ 42s] > cctx = zstd.ZstdCompressor(level=1, threads=2)
[ 42s] E ZstdError: unable to set compression context parameter: Unsupported parameter
[ 42s]
[ 42s] tests/test_compressor.py:375: ZstdError
[ 42s] ________________ TestCompressor_copy_stream.test_multithreaded _________________
[ 42s]
[ 42s] self = <tests.test_compressor.TestCompressor_copy_stream testMethod=test_multithreaded>
[ 42s]
[ 42s] def test_multithreaded(self):
[ 42s] source = io.BytesIO()
[ 42s] source.write(b"a" * 1048576)
[ 42s] source.write(b"b" * 1048576)
[ 42s] source.write(b"c" * 1048576)
[ 42s] source.seek(0)
[ 42s]
[ 42s] dest = io.BytesIO()
[ 42s] > cctx = zstd.ZstdCompressor(threads=2, write_content_size=False)
[ 42s] E ZstdError: unable to set compression context parameter: Unsupported parameter
[ 42s]
[ 42s] tests/test_compressor.py:542: ZstdError
[ 42s] _____________ TestCompressor_stream_writer.test_compression_params _____________
[ 42s]
[ 42s] self = <tests.test_compressor.TestCompressor_stream_writer testMethod=test_compression_params>
[ 42s]
[ 42s] def test_compression_params(self):
[ 42s] params = zstd.ZstdCompressionParameters(
[ 42s] window_log=20,
[ 42s] chain_log=6,
[ 42s] hash_log=12,
[ 42s] min_match=5,
[ 42s] search_log=4,
[ 42s] target_length=10,
[ 42s] > strategy=zstd.STRATEGY_FAST,
[ 42s] )
[ 42s] E SystemError: NULL result without error in PyObject_Call
[ 42s]
[ 42s] tests/test_compressor.py:1088: SystemError
[ 42s] _______________ TestCompressor_stream_writer.test_multithreaded ________________
[ 42s]
[ 42s] self = <tests.test_compressor.TestCompressor_stream_writer testMethod=test_multithreaded>
[ 42s]
[ 42s] def test_multithreaded(self):
[ 42s] dest = NonClosingBytesIO()
[ 42s] > cctx = zstd.ZstdCompressor(threads=2)
[ 42s] E ZstdError: unable to set compression context parameter: Unsupported parameter
[ 42s]
[ 42s] tests/test_compressor.py:1280: ZstdError
[ 42s] ________________ TestCompressor_read_to_iter.test_multithreaded ________________
[ 42s]
[ 42s] self = <tests.test_compressor.TestCompressor_read_to_iter testMethod=test_multithreaded>
[ 42s]
[ 42s] def test_multithreaded(self):
[ 42s] source = io.BytesIO()
[ 42s] source.write(b"a" * 1048576)
[ 42s] source.write(b"b" * 1048576)
[ 42s] source.write(b"c" * 1048576)
[ 42s] source.seek(0)
[ 42s]
[ 42s] > cctx = zstd.ZstdCompressor(threads=2)
[ 42s] E ZstdError: unable to set compression context parameter: Unsupported parameter
[ 42s]
[ 42s] tests/test_compressor.py:1430: ZstdError
[ 42s] ____________________ TestCompressionParameters.test_bounds _____________________
[ 42s]
[ 42s] self = <tests.test_data_structures.TestCompressionParameters testMethod=test_bounds>
[ 42s]
[ 42s] def test_bounds(self):
[ 42s] zstd.ZstdCompressionParameters(
[ 42s] window_log=zstd.WINDOWLOG_MIN,
[ 42s] chain_log=zstd.CHAINLOG_MIN,
[ 42s] hash_log=zstd.HASHLOG_MIN,
[ 42s] search_log=zstd.SEARCHLOG_MIN,
[ 42s] min_match=zstd.MINMATCH_MIN + 1,
[ 42s] target_length=zstd.TARGETLENGTH_MIN,
[ 42s] > strategy=zstd.STRATEGY_FAST,
[ 42s] )
[ 42s] E SystemError: NULL result without error in PyObject_Call
[ 42s]
[ 42s] tests/test_data_structures.py:22: SystemError
[ 42s] ______ TestCompressionParameters.test_estimated_compression_context_size _______
[ 42s]
[ 42s] self = <tests.test_data_structures.TestCompressionParameters testMethod=test_estimated_compression_context_size>
[ 42s]
[ 42s] def test_estimated_compression_context_size(self):
[ 42s] p = zstd.ZstdCompressionParameters(
[ 42s] window_log=20,
[ 42s] chain_log=16,
[ 42s] hash_log=17,
[ 42s] search_log=1,
[ 42s] min_match=5,
[ 42s] target_length=16,
[ 42s] > strategy=zstd.STRATEGY_DFAST,
[ 42s] )
[ 42s] E SystemError: NULL result without error in PyObject_Call
[ 42s]
[ 42s] tests/test_data_structures.py:107: SystemError
[ 42s] __________________ TestCompressionParameters.test_from_level ___________________
[ 42s]
[ 42s] self = <tests.test_data_structures.TestCompressionParameters testMethod=test_from_level>
[ 42s]
[ 42s] def test_from_level(self):
[ 42s] > p = zstd.ZstdCompressionParameters.from_level(1)
[ 42s] E SystemError: error return without exception set
[ 42s]
[ 42s] tests/test_data_structures.py:36: SystemError
[ 42s] _______________ TestCompressionParameters.test_ldm_hash_rate_log _______________
[ 42s]
[ 42s] self = <tests.test_data_structures.TestCompressionParameters testMethod=test_ldm_hash_rate_log>
[ 42s]
[ 42s] def test_ldm_hash_rate_log(self):
[ 42s] with self.assertRaisesRegex(
[ 42s] ValueError, "cannot specify both ldm_hash_rate_log"
[ 42s] ):
[ 42s] > zstd.ZstdCompressionParameters(ldm_hash_rate_log=8, ldm_hash_every_log=4)
[ 42s] E SystemError: NULL result without error in PyObject_Call
[ 42s]
[ 42s] tests/test_data_structures.py:131: SystemError
[ 42s] ____________________ TestCompressionParameters.test_members ____________________
[ 42s]
[ 42s] self = <tests.test_data_structures.TestCompressionParameters testMethod=test_members>
[ 42s]
[ 42s] def test_members(self):
[ 42s] p = zstd.ZstdCompressionParameters(
[ 42s] window_log=10,
[ 42s] chain_log=6,
[ 42s] hash_log=7,
[ 42s] search_log=4,
[ 42s] min_match=5,
[ 42s] target_length=8,
[ 42s] > strategy=1,
[ 42s] )
[ 42s] E SystemError: NULL result without error in PyObject_Call
[ 42s]
[ 42s] tests/test_data_structures.py:52: SystemError
[ 42s] __________________ TestCompressionParameters.test_overlap_log __________________
[ 42s]
[ 42s] self = <tests.test_data_structures.TestCompressionParameters testMethod=test_overlap_log>
[ 42s]
[ 42s] def test_overlap_log(self):
[ 42s] with self.assertRaisesRegex(ValueError, "cannot specify both overlap_log"):
[ 42s] > zstd.ZstdCompressionParameters(overlap_log=1, overlap_size_log=9)
[ 42s] E SystemError: NULL result without error in PyObject_Call
[ 42s]
[ 42s] tests/test_data_structures.py:141: SystemError
[ 42s] ___________________ TestCompressionParameters.test_strategy ____________________
[ 42s]
[ 42s] self = <tests.test_data_structures.TestCompressionParameters testMethod=test_strategy>
[ 42s]
[ 42s] def test_strategy(self):
[ 42s] with self.assertRaisesRegex(
[ 42s] ValueError, "cannot specify both compression_strategy"
[ 42s] ):
[ 42s] > zstd.ZstdCompressionParameters(strategy=0, compression_strategy=0)
[ 42s] E SystemError: NULL result without error in PyObject_Call
[ 42s]
[ 42s] tests/test_data_structures.py:119: SystemError
[ 42s] ________________ TestDecompressor_read_to_iter.test_magic_less _________________
[ 42s]
[ 42s] self = <tests.test_decompressor.TestDecompressor_read_to_iter testMethod=test_magic_less>
[ 42s]
[ 42s] def test_magic_less(self):
[ 42s] params = zstd.CompressionParameters.from_level(
[ 42s] > 1, format=zstd.FORMAT_ZSTD1_MAGICLESS
[ 42s] )
[ 42s] E SystemError: error return without exception set
[ 42s]
[ 42s] tests/test_decompressor.py:1315: SystemError
[ 42s] _______________ TestCompressionDict.test_bad_precompute_compress _______________
[ 42s]
[ 42s] self = <tests.test_train_dictionary.TestCompressionDict testMethod=test_bad_precompute_compress>
[ 42s]
[ 42s] def test_bad_precompute_compress(self):
[ 42s] d = zstd.train_dictionary(8192, generate_samples(), k=64, d=16)
[ 42s]
[ 42s] with self.assertRaisesRegex(ValueError, "must specify one of level or "):
[ 42s] d.precompute_compress()
[ 42s]
[ 42s] with self.assertRaisesRegex(ValueError, "must only specify one of level or "):
[ 42s] d.precompute_compress(
[ 42s] > level=3, compression_params=zstd.CompressionParameters()
[ 42s] )
[ 42s] E SystemError: NULL result without error in PyObject_Call
[ 42s]
[ 42s] tests/test_train_dictionary.py:79: SystemError
[ 42s] =============== 19 failed, 379 passed, 5 skipped in 3.17 seconds ===============
whole build process of this package is weird.
@indygreg https://wiki.gentoo.org/wiki/Why_not_bundle_dependencies
Trying to package this for Fedora and we have a similar policy to Gentoo. I tried deleting the bundled zstd and patching out any remains from make_cffi.py and setup_zstd.py, but the problem is that zstd internals for thread pool management are being used directly (pool.h).
The current state of the main branch is much better than it was a few days ago. We now avoid the private POOL APIs in the C extension when building against an external libzstd. And we should no longer reference the vendored C headers when building the C extension against an external libzstd.
However, the CFFI backend is still referencing the bundled libzstd files during its build. It will need to be taught to build against an external libzstd. At the point the CFFI backend does this, I'll close this issue.
I ran into this today. Alpine Linux recently updated system zstd to 1.5.6 and all of a sudden I got errors:
$ python -c 'import zstandard'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3.12/site-packages/zstandard/__init__.py", line 39, in <module>
from .backend_c import * # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: zstd C API versions mismatch; Python bindings were not compiled/linked against expected zstd version (10506 returned by the lib, 10506 hardcoded in zstd headers, 10505 hardcoded in the cext)