-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Add structured version info for compression modules #117404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
* Add named tuples zlib_version and zlib_runtime_version in the zlib module. * Add string BZLIB_VERSION and named tuple bzlib_version in the bz2 module. * Add strings LZMA_VERSION and LZMA_RUNTIME_VERSION and named tuples lzma_version and lzma_runtime_version in the lzma module.
Thanks for looking at the larger picture. On that Same with string versions, having a properly consumable tuple or numeric version is useful. The strings are a mere convenience. We could do without them but making them available doesn't hurt. I also think we should reconsider the naming: don't include the name prefix on the module member name. It's in the lzma or zlib module, it doesn't need a LZMA_ or ZLIB_ or similar prefix on the name. (It should also be excluded from For existing names that Modules already have, there is no reason to deprecate the existing ones. But adding new ones should use the brief names making the structured version info the simplest one type and get at. Priority:
Everything else is a bonus feature. |
Thank you for your feedback Gregory. Some information and reasoning:
|
The |
#98567 regarding zlib version when linked to zlib-ng is an example of why structured version info is useful. And perhaps why the string version can also be useful: it allows alternative implementations to identify themselves. |
I do not think CPython should be in the business of proactively identifying alternative implementations. There are infinite possibilities there and we'd always be chasing down ones to add specific ID logic for. We should not waste effort on that unsolvable task. ie we should never have a We do not want users to have to use hasattr to try and find attributes that may or may not exist based on some choice someone made at build time. When alternative implementations are used, it is up to them to provide "equivalent to" version numbers. They likely already do for the purposes of being drop in replacement compatible at the C level. |
I don't really care if they are in |
Feature or enhancement
The
zlib
module has two attributes that denote the zlib library version:zlib.ZLIB_VERSION
is the version string of the zlib library that was used for building the module. It was add in cb91404 (Python 1.5).zlib.ZLIB_RUNTIME_VERSION
is the version string of the zlib library actually loaded by the interpreter. It was added in bpo-12306/zlib: Expose zlibVersion to query runtime version of zlib #56515 (Python 3.1).But the version string is not comfortable to use. You need to convert it to a sequence of numbers for comparison, this is boring and errorprone. It would be better to provide a structural version, like
sys.version_info
.Other compression modules do not provide versions at all. The bzlib library has function
BZ2_bzlibVersion()
which returns the version string. The lzma version has a number of constants and functions (LZMA_VERSION_STRING
,LZMA_VERSION
,lzma_version_string()
,lzma_version_number()
) which return static and runtime versions as a string or packed into a number.#115989 by @ivq initially included addition of
lzma.LZMA_VERSION
andlzma.LZMA_RUNTIME_VERSION
for version strings (clearly inspired byzlib
). @gpshead renamed them tolzma.LZMA_HEADER_VERSION_STRING
andlzma.LZMA_VERSION_STRING
and addedlzma.LZMA_HEADER_VERSION
andlzma.LZMA_VERSION
for versions packed into a number.I propose to add attributes for version strings and version named tuples for all compression modules. I think that named tuples are more useful than packed numbers. I created a patch for this, but I am not sure about names. Should we use "RUNTIME_" or "HEADER_" prefixes? Should we add "_STRING" or "_info" suffix? Do we need the version of the library that was used for building the module or the version of the library actually loaded by the interpreter is enough?
Linked PRs
The text was updated successfully, but these errors were encountered: