Skip to content

Commit e56c5ca

Browse files
committed
Make our hexversion and GRAALPY_VERSION_NUM follow the specification
1 parent b5f6a08 commit e56c5ca

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ language runtime. The main focus is on user-observable behavior of the engine.
55

66
## Version 25.0.0
77
* `sys.implementation.version` now returns the GraalPy version instead of the Python version it implements. Also available as `sys.graalpy_version_info` for better discoverability by people already familiar with PyPy and its `sys.pypy_version_info`.
8+
* `GRAALPY_VERSION_NUM` C macro now inlcudes the release level and serial number at the end to conform to the `hexversion` format. This shouldn't break any existing comparisons.
89
* `dir(foreign_object)` now returns both foreign methods and Python methods (it used to return only foreign methods).
910
* Support `__name__`, `__doc__`, `__text_signature__` fields on foreign executables to serve as their proper counterparts on the Python side. This is useful to, for example, use Java functional interfaces in lieu of Python functions for things like LangChain's `@tool` annotation that want to inspect the underlying function.
1011

Diff for: graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_misc.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,12 @@ def test_graalpy_version():
359359
{"get_version_num", (PyCFunction)get_version_num, METH_NOARGS | METH_STATIC, ""}
360360
''',
361361
)
362-
expected_version = __graalpython__.get_graalvm_version().removesuffix('-dev')
363-
assert tester.get_version_str() == expected_version
364-
parts = [int(v) for v in expected_version.split('.')] + [0]
365-
expected_num = 0
366-
for i in range(3):
367-
expected_num <<= 8
368-
expected_num |= parts[i]
369-
assert tester.get_version_num() == expected_num
362+
version = sys.implementation.version
363+
assert tester.get_version_str() == f'{version.major}.{version.minor}.{version.micro}'
364+
assert tester.get_version_num() == sys.implementation.hexversion
365+
# This is an anti-backport trap. The commit that changed the hexversion format should not be backported because
366+
# existing projects might already contain tests for the next feature release in the old format (pybind11 does)
367+
assert version.major >= 25
370368

371369

372370
def test_unicode_docstring():

Diff for: graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysModuleBuiltins.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
package com.oracle.graal.python.builtins.modules;
4242

4343
import static com.oracle.graal.python.PythonLanguage.J_GRAALPYTHON_ID;
44+
import static com.oracle.graal.python.PythonLanguage.RELEASE_LEVEL;
45+
import static com.oracle.graal.python.PythonLanguage.RELEASE_SERIAL;
4446
import static com.oracle.graal.python.PythonLanguage.T_GRAALPYTHON_ID;
4547
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.AttributeError;
4648
import static com.oracle.graal.python.builtins.PythonBuiltinClassType.DeprecationWarning;
@@ -515,7 +517,7 @@ private static PSimpleNamespace makeImplementation(PythonLanguage language, PTup
515517
"-" + PythonLanguage.MAJOR + PythonLanguage.MINOR));
516518
ns.setAttribute(T_VERSION, graalpyVersionInfo);
517519
ns.setAttribute(T__MULTIARCH, gmultiarch);
518-
ns.setAttribute(tsLiteral("hexversion"), PythonLanguage.GRAALVM_MAJOR << 16 | PythonLanguage.GRAALVM_MINOR << 8 | PythonLanguage.GRAALVM_MICRO);
520+
ns.setAttribute(tsLiteral("hexversion"), PythonLanguage.GRAALVM_MAJOR << 24 | PythonLanguage.GRAALVM_MINOR << 16 | PythonLanguage.GRAALVM_MICRO << 8 | RELEASE_LEVEL << 4 | RELEASE_SERIAL);
519521
return ns;
520522
}
521523

Diff for: mx.graalpython/mx_graalpython.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,8 @@ def graal_version_short(variant=None, **kwargs):
18611861
for i in range(3):
18621862
num <<= 8
18631863
num |= int(parts[i]) if i < len(parts) else 0
1864+
num <<= 8
1865+
num |= release_level('int') << 4
18641866
return hex(num)
18651867
else:
18661868
return '.'.join(GRAAL_VERSION.split('.')[:3])
@@ -1871,14 +1873,16 @@ def release_level(variant=None):
18711873
level = 'alpha'
18721874
if SUITE.suiteDict['release']:
18731875
level = 'final'
1874-
if variant == 'binary':
1876+
if variant in ('binary', 'int'):
18751877
level_num = {
18761878
'alpha': 0xA,
18771879
'beta': 0xB,
18781880
'candidate': 0xC,
18791881
'final': 0xF,
18801882
}[level]
1881-
return chr(level_num + ord(VERSION_BASE))
1883+
if variant == 'binary':
1884+
return chr(level_num + ord(VERSION_BASE))
1885+
return level_num
18821886
return level
18831887

18841888

0 commit comments

Comments
 (0)