Skip to content

Commit decdb3c

Browse files
committed
Add sys.graalpy_version_info and set sys.implementation.version to it
Fixes #487
1 parent ab81526 commit decdb3c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -506,16 +506,16 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
506506
return SysModuleBuiltinsFactory.getFactories();
507507
}
508508

509-
private static PSimpleNamespace makeImplementation(PythonLanguage language, PTuple versionInfo, TruffleString gmultiarch) {
509+
private static PSimpleNamespace makeImplementation(PythonLanguage language, PTuple graalpyVersionInfo, TruffleString gmultiarch) {
510510
final PSimpleNamespace ns = PFactory.createSimpleNamespace(language);
511511
ns.setAttribute(tsLiteral("name"), T_GRAALPYTHON_ID);
512512
/*- 'cache_tag' must match the format of mx.graalpython/mx_graalpython.py:graalpy_ext */
513513
ns.setAttribute(T_CACHE_TAG, toTruffleStringUncached(J_GRAALPYTHON_ID +
514514
PythonLanguage.GRAALVM_MAJOR + PythonLanguage.GRAALVM_MINOR + PythonLanguage.DEV_TAG +
515515
"-" + PythonLanguage.MAJOR + PythonLanguage.MINOR));
516-
ns.setAttribute(T_VERSION, versionInfo);
516+
ns.setAttribute(T_VERSION, graalpyVersionInfo);
517517
ns.setAttribute(T__MULTIARCH, gmultiarch);
518-
ns.setAttribute(tsLiteral("hexversion"), PythonLanguage.VERSION_HEX);
518+
ns.setAttribute(tsLiteral("hexversion"), PythonLanguage.GRAALVM_MAJOR << 16 | PythonLanguage.GRAALVM_MINOR << 8 | PythonLanguage.GRAALVM_MICRO);
519519
return ns;
520520
}
521521

@@ -588,7 +588,10 @@ public void initialize(Python3Core core) {
588588
addBuiltinConstant(T_STDOUT, PNone.NONE);
589589
addBuiltinConstant(T_STDERR, PNone.NONE);
590590

591-
addBuiltinConstant("implementation", makeImplementation(language, versionInfo, gmultiarch));
591+
PTuple graalpyVersion = PFactory.createStructSeq(language, VERSION_INFO_DESC, PythonLanguage.GRAALVM_MAJOR, PythonLanguage.GRAALVM_MINOR, PythonLanguage.GRAALVM_MICRO,
592+
PythonLanguage.RELEASE_LEVEL_STRING, PythonLanguage.RELEASE_SERIAL);
593+
addBuiltinConstant("graalpy_version_info", graalpyVersion);
594+
addBuiltinConstant("implementation", makeImplementation(language, graalpyVersion, gmultiarch));
592595
addBuiltinConstant("hexversion", PythonLanguage.VERSION_HEX);
593596

594597
if (os == PLATFORM_WIN32) {

0 commit comments

Comments
 (0)