Skip to content

Commit 1492d7d

Browse files
committed
expose Min/MaxSupportedVersion and IsSupportedVersion on PythonEngine
fixes #1724
1 parent 987b2ee commit 1492d7d

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ See [Mixins/collections.py](src/runtime/Mixins/collections.py).
2828
and other `PyObject` derived types when called from Python.
2929
- .NET classes, that have `__call__` method are callable from Python
3030
- `PyIterable` type, that wraps any iterable object in Python
31+
- `PythonEngine` properties for supported Python versions: `MinSupportedVersion`, `MaxSupportedVersion`, and `IsSupportedVersion`
3132

3233

3334
### Changed

src/runtime/PythonEngine.cs

+4
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ public static string PythonPath
127127
}
128128
}
129129

130+
public static Version MinSupportedVersion => new(3, 7);
131+
public static Version MaxSupportedVersion => new(3, 10, int.MaxValue, int.MaxValue);
132+
public static bool IsSupportedVersion(Version version) => version >= MinSupportedVersion && version <= MaxSupportedVersion;
133+
130134
public static string Version
131135
{
132136
get { return Marshal.PtrToStringAnsi(Runtime.Py_GetVersion()); }

tests/test_engine.py

+8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ def test_multiple_calls_to_initialize():
1919
assert False # Initialize() raise an exception.
2020

2121

22+
def test_supported_version():
23+
major, minor, build, *_ = sys.version_info
24+
ver = System.Version(major, minor, build)
25+
assert PythonEngine.IsSupportedVersion(ver)
26+
assert ver >= PythonEngine.MinSupportedVersion
27+
assert ver <= PythonEngine.MaxSupportedVersion
28+
29+
2230
@pytest.mark.skip(reason="FIXME: test crashes")
2331
def test_import_module():
2432
"""Test module import."""

0 commit comments

Comments
 (0)