https://github.com/python/cpython/commit/c141d4393750c827cbcb3867f0f42997a3bb3528
commit: c141d4393750c827cbcb3867f0f42997a3bb3528
branch: main
author: Donghee Na <[email protected]>
committer: corona10 <[email protected]>
date: 2024-05-18T19:44:40Z
summary:
gh-119132: Update sys.version to identify free-threaded or not. (gh-119134)
files:
A Misc/NEWS.d/next/Build/2024-05-17-19-53-27.gh-issue-119132.wepPgM.rst
M Lib/platform.py
M Python/getversion.c
diff --git a/Lib/platform.py b/Lib/platform.py
index ebaba37563120e..5958382276e79c 100755
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -1153,17 +1153,16 @@ def _sys_version(sys_version=None):
if result is not None:
return result
- sys_version_parser = re.compile(
- r'([\w.+]+)\s*' # "version<space>"
- r'\(#?([^,]+)' # "(#buildno"
- r'(?:,\s*([\w ]*)' # ", builddate"
- r'(?:,\s*([\w :]*))?)?\)\s*' # ", buildtime)<space>"
- r'\[([^\]]+)\]?', re.ASCII) # "[compiler]"
-
if sys.platform.startswith('java'):
# Jython
+ jython_sys_version_parser = re.compile(
+ r'([\w.+]+)\s*' # "version<space>"
+ r'\(#?([^,]+)' # "(#buildno"
+ r'(?:,\s*([\w ]*)' # ", builddate"
+ r'(?:,\s*([\w :]*))?)?\)\s*' # ", buildtime)<space>"
+ r'\[([^\]]+)\]?', re.ASCII) # "[compiler]"
name = 'Jython'
- match = sys_version_parser.match(sys_version)
+ match = jython_sys_version_parser.match(sys_version)
if match is None:
raise ValueError(
'failed to parse Jython sys.version: %s' %
@@ -1190,7 +1189,14 @@ def _sys_version(sys_version=None):
else:
# CPython
- match = sys_version_parser.match(sys_version)
+ cpython_sys_version_parser = re.compile(
+ r'([\w.+]+)\s*' # "version<space>"
+ r'(?:experimental free-threading build\s+)?' #
"free-threading-build<space>"
+ r'\(#?([^,]+)' # "(#buildno"
+ r'(?:,\s*([\w ]*)' # ", builddate"
+ r'(?:,\s*([\w :]*))?)?\)\s*' # ", buildtime)<space>"
+ r'\[([^\]]+)\]?', re.ASCII) # "[compiler]"
+ match = cpython_sys_version_parser.match(sys_version)
if match is None:
raise ValueError(
'failed to parse CPython sys.version: %s' %
diff --git
a/Misc/NEWS.d/next/Build/2024-05-17-19-53-27.gh-issue-119132.wepPgM.rst
b/Misc/NEWS.d/next/Build/2024-05-17-19-53-27.gh-issue-119132.wepPgM.rst
new file mode 100644
index 00000000000000..44fe2a1a1f6725
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2024-05-17-19-53-27.gh-issue-119132.wepPgM.rst
@@ -0,0 +1,2 @@
+Update :data:`sys.version` to identify whether the build is default build or
+free-threading build. Patch By Donghee Na.
diff --git a/Python/getversion.c b/Python/getversion.c
index 5db836ab4bfd6d..226b2f999a6bfd 100644
--- a/Python/getversion.c
+++ b/Python/getversion.c
@@ -6,7 +6,7 @@
#include "patchlevel.h"
static int initialized = 0;
-static char version[250];
+static char version[300];
void _Py_InitVersion(void)
{
@@ -14,7 +14,12 @@ void _Py_InitVersion(void)
return;
}
initialized = 1;
- PyOS_snprintf(version, sizeof(version), "%.80s (%.80s) %.80s",
+#ifdef Py_GIL_DISABLED
+ const char *buildinfo_format = "%.80s experimental free-threading build
(%.80s) %.80s";
+#else
+ const char *buildinfo_format = "%.80s (%.80s) %.80s";
+#endif
+ PyOS_snprintf(version, sizeof(version), buildinfo_format,
PY_VERSION, Py_GetBuildInfo(), Py_GetCompiler());
}
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]