From e781e95c92acaa1be7f017edb3bfcf75468af16d Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Tue, 23 Dec 2025 21:00:04 -0500 Subject: [PATCH] Add a python version identifier Closes https://github.com/llnl/zfp/issues/280 --- CHANGELOG.md | 1 + python/zfpy.pxd | 1 + python/zfpy.pyx | 2 ++ tests/python/test_numpy.py | 5 +++++ 4 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7903a4210..7a6089b07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Change Log - A new code example, `chunk`, shows how to perform (de)compression in chunks. - A new utility function `zfp_block_maximum_size()` returns maximum block size for given scalar type, dimensionality, and compression mode. +- `zfpy.__version__` for straightfoward access to the zfp version string in Python. ### Fixed diff --git a/python/zfpy.pxd b/python/zfpy.pxd index 067bd90a4..87aea2cf3 100644 --- a/python/zfpy.pxd +++ b/python/zfpy.pxd @@ -11,6 +11,7 @@ cdef extern from "zfp/bitstream.h": void stream_close(bitstream* stream) cdef extern from "zfp.h": + cython.char * ZFP_VERSION_STRING # enums ctypedef enum zfp_type: zfp_type_none = 0, diff --git a/python/zfpy.pyx b/python/zfpy.pyx index 0d1eb5230..89b455cfc 100644 --- a/python/zfpy.pyx +++ b/python/zfpy.pyx @@ -37,6 +37,8 @@ mode_fixed_rate = zfp_mode_fixed_rate mode_fixed_precision = zfp_mode_fixed_precision mode_fixed_accuracy = zfp_mode_fixed_accuracy +__version__ = str(ZFP_VERSION_STRING, encoding='utf-8') + cpdef dtype_to_ztype(dtype): if dtype == np.int32: diff --git a/tests/python/test_numpy.py b/tests/python/test_numpy.py index 4f822c916..189aa430b 100644 --- a/tests/python/test_numpy.py +++ b/tests/python/test_numpy.py @@ -10,6 +10,11 @@ except ImportError: version_parse = None +def test_zfpy_version(): + # Just ensure that the version contains 3 numbers separated by dots + assert len(zfpy.__version__.split('.')) == 3 + # Ensure it is a string, not bytes + assert isinstance(zfpy.__version__, str) class TestNumpy(unittest.TestCase): def lossless_round_trip(self, orig_array):