Skip to content

Min/MaxSupportedVersion and IsSupportedVersion on PythonEngine #1798

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 1 commit into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ See [Mixins/collections.py](src/runtime/Mixins/collections.py).
and other `PyObject` derived types when called from Python.
- .NET classes, that have `__call__` method are callable from Python
- `PyIterable` type, that wraps any iterable object in Python
- `PythonEngine` properties for supported Python versions: `MinSupportedVersion`, `MaxSupportedVersion`, and `IsSupportedVersion`


### Changed
Expand Down
4 changes: 4 additions & 0 deletions src/runtime/PythonEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ public static string PythonPath
}
}

public static Version MinSupportedVersion => new(3, 7);
public static Version MaxSupportedVersion => new(3, 10, int.MaxValue, int.MaxValue);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe something more "readable", like 999 instead of maxint?

Copy link
Member Author

@lostmsu lostmsu May 26, 2022

Choose a reason for hiding this comment

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

I thought of that, but it won't work if there are builds of Python that use build number not as patch (e.g. patch .4), but in a Windows manner like .19041.365, or maybe do MaxSupportedVersionExclusive. Alternatively, we can only leave the IsSupportedVersion check and provide an error string in a separate property.

What do you think?

public static bool IsSupportedVersion(Version version) => version >= MinSupportedVersion && version <= MaxSupportedVersion;

public static string Version
{
get { return Marshal.PtrToStringAnsi(Runtime.Py_GetVersion()); }
Expand Down
8 changes: 8 additions & 0 deletions tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ def test_multiple_calls_to_initialize():
assert False # Initialize() raise an exception.


def test_supported_version():
major, minor, build, *_ = sys.version_info
ver = System.Version(major, minor, build)
assert PythonEngine.IsSupportedVersion(ver)
assert ver >= PythonEngine.MinSupportedVersion
assert ver <= PythonEngine.MaxSupportedVersion


@pytest.mark.skip(reason="FIXME: test crashes")
def test_import_module():
"""Test module import."""
Expand Down