8000 gh-119132: Update sys.version to identify free-threaded or not. by corona10 · Pull Request #119134 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-119132: Update sys.version to identify free-threaded or not. #119134

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 13 commits into from
May 18, 2024
Merged
Prev Previous commit
Next Next commit
Address code review
  • Loading branch information
corona10 committed May 18, 2024
commit e2d60ba3ccc52668d0b6eef3920093b6bc8207f5
23 changes: 18 additions & 5 deletions Lib/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -1155,16 +1155,22 @@ def _sys_version(sys_version=None):

sys_version_parser = re.compile(
r'([\w.+]+)\s*' # "version<space>"
r'(free-threading)?\s*'
r'\(#?([^,]+)' # "(#buildno"
r'(?:,\s*([\w ]*)' # ", builddate"
r'(?:,\s*([\w :]*))?)?' # ", buildtime"
r'(?:,\s*(free-threading))?\)*\s*' # ",'free-threading')<space>'"
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' %
Expand All @@ -1191,12 +1197,19 @@ 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'(free-threading)?\s*'
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' %
repr(sys_version))
version, buildno, builddate, buildtime, _, compiler = \
version, _, buildno, builddate, buildtime, compiler = \
match.groups()
name = 'CPython'
if builddate is None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Add build information to identify whether the build is default build or
Update data:`sys.version` to identify whether the build is default build or
free-threading build. Patch By Donghee Na.
7 changes: 0 additions & 7 deletions Modules/getbuildinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,9 @@ Py_GetBuildInfo(void)
if (!(*gitid)) {
gitid = "main";
}
#ifdef Py_GIL_DISABLED
const char *build = "free-threading";
PyOS_snprintf(buildinfo, sizeof(buildinfo),
"%s%s%s, %.20s, %.9s, %s", gitid, sep, revision,
DATE, TIME, build);
#else
PyOS_snprintf(buildinfo, sizeof(buildinfo),
"%s%s%s, %.20s, %.9s", gitid, sep, revision,
DATE, TIME);
#endif
return buildinfo;
}

Expand Down
7 changes: 6 additions & 1 deletion Python/getversion.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 free-threading (%.80s) %.80s";
#else
const char *buildinfo_format = "%.80s (%.80s) %.80s";
#endif
PyOS_snprintf(version, sizeof(version), buildinfo_format,
PY_VERSION, Py_GetBuildInfo(), Py_GetCompiler());
}

Expand Down
Loading
0