-
Notifications
You must be signed in to change notification settings - Fork 854
Allow parsing exotic python version #4949
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
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" ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, sorry this caused a crash for you. I have one further suggestion just for completeness...
@@ -44,9 +44,6 @@ impl<'a> PythonVersionInfo<'a> { | |||
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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's perhaps use splitn
on line 43 so that the patch_str
will contain any "exotic" part?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, just did.
@@ -139,5 +136,6 @@ mod test { | |||
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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be nice in here to assert that the "suffix" is +chromium.29
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I've updated the test
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, thanks!
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
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
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
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: