Allow parsing exotic python version#4949
Merged
davidhewitt merged 2 commits intoPyO3:mainfrom Mar 1, 2025
Merged
Conversation
On specific linux disto, the python version output can be exotic. For example, in my machine I got the following: ``` ❯ python --version Python 3.11.3+chromium.29 ``` Which can lead to not desired end of program: ``` from cryptography.hazmat.bindings._rust import openssl as rust_openssl pyo3_runtime.PanicException: called `Result::unwrap()` on an `Err` value: "Python version string has too many parts" ```
davidhewitt
reviewed
Feb 28, 2025
Member
davidhewitt
left a comment
There was a problem hiding this comment.
Thanks, sorry this caused a crash for you. I have one further suggestion just for completeness...
| let major_str = parts.next().ok_or("Python major version missing")?; | ||
| let minor_str = parts.next().ok_or("Python minor version missing")?; | ||
| let patch_str = parts.next(); | ||
| if parts.next().is_some() { |
Member
There was a problem hiding this comment.
Let's perhaps use splitn on line 43 so that the patch_str will contain any "exotic" part?
| assert!(PythonVersionInfo::from_str("3.5+").unwrap() == (3, 5)); | ||
| assert!(PythonVersionInfo::from_str("3.5.2a1+").unwrap() < (3, 6)); | ||
| assert!(PythonVersionInfo::from_str("3.5.2a1+").unwrap() > (3, 4)); | ||
| assert!(PythonVersionInfo::from_str("3.11.3+chromium.29").unwrap() >= (3, 11, 3)); |
Member
There was a problem hiding this comment.
It might be nice in here to assert that the "suffix" is +chromium.29.
Contributor
Author
There was a problem hiding this comment.
Sure, I've updated the test
Member
|
Also, please add a "fixed" newsfragment for the changelog. |
* add test to check if the suffix is properly capture * add newsfragment "fixed" entry for the changelog
SilverBzH
added a commit
to SilverBzH/cryptography
that referenced
this pull request
Mar 17, 2025
pyo3 version prior to 0.24.0 are not able to parse properly exotic python version. This is fix since PyO3/pyo3#4949 available on the v0.24.0 version
shubhamdp
added a commit
to shubhamdp/connectedhomeip
that referenced
this pull request
Jun 19, 2025
bootstrapping the environment will install the chromium based python and it when "python3 --version" would result into "Python 3.11.3+chromium.29". With cryptography v43.0.0, parsing such python version would fail even if we try to import the cryptography module. It was fixed in pyo3 repository PR:PyO3/pyo3#4949 and this fix was part of cryptography module onwards v44.0.3
shubhamdp
added a commit
to shubhamdp/connectedhomeip
that referenced
this pull request
Jun 19, 2025
bootstrapping the environment will install the chromium based python and it when "python3 --version" would result into "Python 3.11.3+chromium.29". With cryptography v43.0.0, parsing such python version would fail even if we try to import the cryptography module. It was fixed in pyo3 repository PR:PyO3/pyo3#4949 and this fix was part of cryptography module onwards v45.0.1
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On specific linux disto, the python version output can be exotic.
For example, in my machine I got the following:
Which can lead to not desired end of program: