Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Doc/library/bz2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,31 @@ One-shot (de)compression
.. versionchanged:: 3.3
Support for multi-stream inputs was added.


Miscellaneous
-------------

Information about the version of the bzip2 compression library in use
is available through the following constants:


.. data:: bzlib_version

The version string of the bzip2 compression library.

.. versionadded:: next


.. data:: bzlib_version_info

A named tuple containing the three components of the bzip2 compression
library version: *major*, *minor*, and *patch*. All values are integers.
The components can also be accessed by name, so ``bz2.bzlib_version_info[0]``
is equivalent to ``bz2.bzlib_version_info.major`` and so on.

.. versionadded:: next


.. _bz2-usage-examples:

Examples of usage
Expand Down
39 changes: 36 additions & 3 deletions Doc/library/compression.zstd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -827,10 +827,43 @@ Miscellaneous
The default compression level for Zstandard: ``3``.


.. attribute:: zstd_version_info
Information about the version of the zstd library in use is available through
the following constants:

Version number of the runtime zstd library as a tuple of integers
(major, minor, release).

.. data:: ZSTD_VERSION

The version string of the zstd library that was used for building the module.
This may be different from the zstd library actually used at runtime, which
is available as :const:`zstd_version`.

.. versionadded:: next


.. data:: zstd_version

The version string of the zstd library actually loaded by the interpreter.


.. data:: ZSTD_VERSION_INFO

A named tuple containing the four components of the zstd library
version that was used for building the module:
*major*, *minor*, and *patch*. All values are integers.
The components can also be accessed by name, so ``zstd.ZSTD_VERSION_INFO[0]``
is equivalent to ``zstd.ZSTD_VERSION_INFO.major`` and so on.
This may be different from the zstd library actually used at runtime, which
is available as :const:`zstd_version_info`.

.. versionadded:: next


.. data:: zstd_version_info

A named tuple containing the zstd library version actually loaded by the interpreter.

.. versionchanged:: next
It is now a named tuple.


Examples
Expand Down
42 changes: 42 additions & 0 deletions Doc/library/lzma.rst
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,48 @@ Miscellaneous
feature set.


Information about the version of the lzma library in use is available through
the following constants:


.. data:: LZMA_VERSION

The version string of the lzma library that was used for building the module.
This may be different from the lzma library actually used at runtime, which
is available as :const:`lzma_version`.

.. versionadded:: next


.. data:: lzma_version

The version string of the lzma library actually loaded by the interpreter.

.. versionadded:: next


.. data:: LZMA_VERSION_INFO

A named tuple containing the four components of the lzma library
version that was used for building the module:
*major*, *minor*, *patch*, and *stability*.
All values except *stability* are integers; *stability* is ``'alpha'``,
``'beta'``, or ``'stable'``.
The components can also be accessed by name, so ``lzma.LZMA_VERSION_INFO[0]``
is equivalent to ``lzma.LZMA_VERSION_INFO.major`` and so on.
This may be different from the lzma library actually used at runtime, which
is available as :const:`lzma_version_info`.

.. versionadded:: next


.. data:: lzma_version_info

A named tuple containing the lzma library version actually loaded by the interpreter.

.. versionadded:: next


.. _filter-chain-specs:

Specifying custom filter chains
Expand Down
43 changes: 38 additions & 5 deletions Doc/library/zlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -479,27 +479,60 @@ the following constants:

The version string of the zlib library that was used for building the module.
This may be different from the zlib library actually used at runtime, which
is available as :const:`ZLIB_RUNTIME_VERSION`.
is available as :const:`zlib_version`.


.. data:: ZLIB_RUNTIME_VERSION
.. data:: zlib_version

The version string of the zlib library actually loaded by the interpreter.

.. versionadded:: 3.3
.. versionchanged:: next
Added alias :const:`!zlib_version`.


.. data:: ZLIB_VERSION_INFO

A named tuple containing the four components of the zlib library
version that was used for building the module:
*major*, *minor*, *revision*, and *subversion*.
All values are integers.
The components can also be accessed by name, so ``zlib.VERSION_INFO[0]``
is equivalent to ``zlib.VERSION_INFO.major`` and so on.
This may be different from the zlib library actually used at runtime, which
is available as :const:`zlib_version_info`.

.. versionadded:: next


.. data:: zlib_version_info

A named tuple containing the zlib library version actually loaded by the interpreter.

.. versionadded:: next


The following constants are only present if zlib-ng was used to build
the module:


.. data:: ZLIBNG_VERSION

The version string of the zlib-ng library that was used for building the
module if zlib-ng was used. When present, the :data:`ZLIB_VERSION` and
:data:`ZLIB_RUNTIME_VERSION` constants reflect the version of the zlib API
module if zlib-ng was used. When present, the :const:`ZLIB_VERSION` and
:const:`zlib_version` constants reflect the version of the zlib API
provided by zlib-ng.

If zlib-ng was not used to build the module, this constant will be absent.

.. versionadded:: 3.14

.. data:: ZLIBNG_VERSION_INFO

A named tuple containing the version of the zlib-ng library that was
used for building the module if zlib-ng was used.

.. versionadded:: next


.. seealso::

Expand Down
33 changes: 33 additions & 0 deletions Doc/whatsnew/3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ New modules
Improved modules
================

bz2
---

* Added constants :const:`~bz2.bzlib_version` and
:const:`~bz2.bzlib_version_info` which provide information about
the version of the bzip2 compression library in use.
(Contributed by Serhiy Storchaka in :gh:`117404`.)

compression.zstd
----------------

* Added constants :const:`~compression.zstd.ZSTD_VERSION` and
:const:`~compression.zstd.ZSTD_VERSION_INFO` which provide information
about the version of the zstd library that was used for building the module.
:const:`~compression.zstd.zstd_version_info` is now a named tuple.
(Contributed by Serhiy Storchaka in :gh:`117404`.)

gzip
----

Expand All @@ -102,6 +119,11 @@ lzma
requires ``lzma`` 5.4.0 or newer while RISC-V requires 5.6.0 or newer.
(Contributed by Chien Wong in :gh:`115988`.)

* Added constants :const:`~lzma.LZMA_VERSION`, :const:`~lzma.lzma_version`,
:const:`~lzma.LZMA_VERSION_INFO`, and :const:`~lzma.lzma_version_info`,
which provide information about the version of the lzma library in use.
(Contributed by Serhiy Storchaka in :gh:`117404`.)

os
--

Expand All @@ -124,6 +146,17 @@ xml
instead of failing later, when encounter non-ASCII data.
(Contributed by Serhiy Storchaka in :gh:`62259`.)

zlib
----

* Added constants :const:`~zlib.ZLIB_VERSION_INFO`,
:const:`~zlib.zlib_version_info`, and :const:`~zlib.ZLIBNG_VERSION_INFO`,
which provide information about the version of the zlib and the zlib-ng
libraries in use.
Added :const:`~zlib.zlib_version` as an alias of
:const:`~zlib.ZLIB_RUNTIME_VERSION`.
(Contributed by Serhiy Storchaka in :gh:`117404`.)

.. Add improved modules above alphabetically, not here at the end.

Optimizations
Expand Down
4 changes: 2 additions & 2 deletions Lib/bz2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

__all__ = ["BZ2File", "BZ2Compressor", "BZ2Decompressor",
"open", "compress", "decompress"]
"open", "compress", "decompress", "bzlib_version", "bzlib_version_info"]

__author__ = "Nadeem Vawda <nadeem.vawda@gmail.com>"

Expand All @@ -14,7 +14,7 @@
import io
import os

from _bz2 import BZ2Compressor, BZ2Decompressor
from _bz2 import BZ2Compressor, BZ2Decompressor, bzlib_version, bzlib_version_info


# Value 0 no longer used
Expand Down
9 changes: 4 additions & 5 deletions Lib/compression/zstd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
'get_frame_size',
'zstd_version',
'zstd_version_info',
'ZSTD_VERSION',
'ZSTD_VERSION_INFO',
'ZstdCompressor',
'ZstdDecompressor',
'ZstdDict',
Expand All @@ -29,13 +31,10 @@
import _zstd
import enum
from _zstd import (ZstdCompressor, ZstdDecompressor, ZstdDict, ZstdError,
get_frame_size, zstd_version)
get_frame_size, zstd_version, ZSTD_VERSION,
zstd_version_info, ZSTD_VERSION_INFO)
from compression.zstd._zstdfile import ZstdFile, open, _nbytes

# zstd_version_number is (MAJOR * 100 * 100 + MINOR * 100 + RELEASE)
zstd_version_info = (*divmod(_zstd.zstd_version_number // 100, 100),
_zstd.zstd_version_number % 100)
"""Version number of the runtime zstd library as a tuple of integers."""

COMPRESSION_LEVEL_DEFAULT = _zstd.ZSTD_CLEVEL_DEFAULT
"""The default compression level for Zstandard, currently '3'."""
Expand Down
1 change: 1 addition & 0 deletions Lib/lzma.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

"LZMACompressor", "LZMADecompressor", "LZMAFile", "LZMAError",
"open", "compress", "decompress", "is_check_supported",
"lzma_version", "lzma_version_info", "LZMA_VERSION", "LZMA_VERSION_INFO",
]

import builtins
Expand Down
24 changes: 22 additions & 2 deletions Lib/test/pythoninfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,17 +660,37 @@ def collect_zlib(info_add):
except ImportError:
return

attributes = ('ZLIB_VERSION', 'ZLIB_RUNTIME_VERSION', 'ZLIBNG_VERSION')
attributes = ('ZLIB_VERSION', 'zlib_version', 'ZLIBNG_VERSION')
copy_attributes(info_add, zlib, 'zlib.%s', attributes)


def collect_bz2(info_add):
try:
import _bz2
except ImportError:
return

attributes = ('bzlib_version',)
copy_attributes(info_add, _bz2, 'bz2.%s', attributes)


def collect_lzma(info_add):
try:
import _lzma
except ImportError:
return

attributes = ('LZMA_VERSION', 'lzma_version')
copy_attributes(info_add, _lzma, 'lzma.%s', attributes)


def collect_zstd(info_add):
try:
import _zstd
except ImportError:
return

attributes = ('zstd_version',)
attributes = ('ZSTD_VERSION', 'zstd_version')
copy_attributes(info_add, _zstd, 'zstd.%s', attributes)


Expand Down
25 changes: 25 additions & 0 deletions Lib/test/test_bz2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,31 @@ def test_newline(self):
self.assertEqual(f.readlines(), [text])


class MiscTests(unittest.TestCase):

def test_bzlib_version(self):
if support.verbose:
print(f'bzlib_version = {bz2.bzlib_version}', flush=True)
print(f'bzlib_version_info = {bz2.bzlib_version_info}', flush=True)
v = bz2.bzlib_version_info
self.assertIsInstance(v[:], tuple)
self.assertEqual(len(v), 3)
self.assertIsInstance(v[0], int)
self.assertIsInstance(v[1], int)
self.assertIsInstance(v[2], int)
self.assertIsInstance(v.major, int)
self.assertIsInstance(v.minor, int)
self.assertIsInstance(v.patch, int)
self.assertEqual(v[0], v.major)
self.assertEqual(v[1], v.minor)
self.assertEqual(v[2], v.patch)
self.assertGreaterEqual(v.major, 0)
self.assertGreaterEqual(v.minor, 0)
self.assertGreaterEqual(v.patch, 0)

self.assertEqual(bz2.bzlib_version.split(',')[0], '%d.%d.%d' % v)


def tearDownModule():
support.reap_children()

Expand Down
Loading
Loading