Skip to content

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

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
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
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