-
Notifications
You must be signed in to change notification settings - Fork 806
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
Allow parsing exotic python version #4949
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!
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: