Skip to content
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

Merged
merged 2 commits into from
Mar 1, 2025
Merged

Allow parsing exotic python version #4949

merged 2 commits into from
Mar 1, 2025

Conversation

SilverBzH
Copy link
Contributor

@SilverBzH SilverBzH commented Feb 27, 2025

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"

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"
```
Copy link
Member

@davidhewitt davidhewitt left a 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() {
Copy link
Member

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?

Copy link
Contributor Author

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));
Copy link
Member

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.

Copy link
Contributor Author

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

@davidhewitt
Copy link
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
Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks!

@davidhewitt davidhewitt added this pull request to the merge queue Feb 28, 2025
Merged via the queue into PyO3:main with commit 5e95edd Mar 1, 2025
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants