1717# Get PY_VERSION from Include/patchlevel.h
1818PY_VERSION_REGEX = re .compile (r'^#define PY_VERSION +"(.*)"$' , re .MULTILINE )
1919
20- # Parse verbose Clang version (truncated here with '...'):
21- # 'Clang 24.0.0git (https:/github.com/llvm/llvm-project a06...8bf)'
22- # 'Android (13691557, +pgo, ...) clang version 18.0.4 (https://android.googlesource.com/toolchain/llvm-project d80...262)'
23- CLANG_VERBOSE_VERSION = re .compile (r'(Clang .*|clang version .*) \(https:/.*\)' )
24-
25- # Parse short Clang version: 'clang version 18.0.4'
26- CLANG_SHORT_VERSION = re .compile (r'clang version (.*)' )
20+ # Parse Clang version (truncated examples using '...'):
21+ # 'Clang 21.0.0 (clang-2100.1.1.101)'
22+ # 'clang version 18.0.4'
23+ # 'Apple clang version 21.0.0 (clang-2100.1.1.101)'
24+ # 'Clang 18.0.4 (https://android.googlesource.com/toolchain/llvm-project d80...62)'
25+ CLANG_VERSION_REGEX = re .compile (
26+ r'(?:([A-Za-z_-][A-Za-z_ -]+) .*)?' # Vendor name: 'Android' or 'Apple'
27+ r'(?:Clang|clang version) ' # 'Clang' or 'clang version'
28+ r'([0-9]+\.[0-9a-z.+]+)' # version
29+ )
2730
2831
2932def exit_error (msg ):
@@ -48,7 +51,7 @@ def get_makefile_vars():
4851 return sysconfig .__main__ ._parse_makefile (makefile )
4952
5053
51- def get_gil_disable ():
54+ def get_gil_disabled ():
5255 # Look in the current working directory
5356 pyconfig_h = 'pyconfig.h'
5457 with open (pyconfig_h , encoding = "utf-8" ) as fp :
@@ -83,8 +86,7 @@ def get_build_info(git_tag, git_branch, git_version):
8386 git_id = "main"
8487
8588 sep = ":" if git_version else ""
86-
87- build_info = f"{ git_id } { sep } { git_version } , { build_date :.20s} , { build_time :.9s} "
89+ build_info = f"{ git_id } { sep } { git_version } , { build_date } , { build_time } "
8890 return (build_info , git_id )
8991
9092
@@ -140,7 +142,7 @@ def _get_compiler():
140142 if compiler :
141143 return compiler
142144
143- # Running _getcompiler failed, run directly the compiler ( --version)
145+ # Running _getcompiler failed, run the compiler with --version
144146 CC = makefile_vars .get ('CC' )
145147 if not CC :
146148 exit_error (f"ERROR: Unable to locate CC in Makefile" )
@@ -154,16 +156,15 @@ def _get_compiler():
154156 return None
155157
156158
157- def shorter_clang_version (compiler ):
158- # Make verbose Clang version shorter: strip the prefix and URL
159- match = CLANG_VERBOSE_VERSION .search (compiler )
159+ def compact_compiler (compiler ):
160+ match = CLANG_VERSION_REGEX .search (compiler )
160161 if match :
161- compiler = match .group (1 )
162-
163- # Use a full match: don't replace 'Apple clang version 21.0.0' for example
164- match = CLANG_SHORT_VERSION . fullmatch ( compiler )
165- if match :
166- compiler = 'Clang ' + match . group ( 1 )
162+ vendor = match .group (1 )
163+ version = match . group ( 2 )
164+ if vendor :
165+ compiler = f' { vendor } Clang { version } '
166+ else :
167+ compiler = f 'Clang { version } '
167168
168169 return compiler
169170
@@ -176,7 +177,7 @@ def get_compiler(compiler):
176177 # (see Programs/_getcompiler.c)
177178 compiler = 'C'
178179
179- compiler = shorter_clang_version (compiler )
180+ compiler = compact_compiler (compiler )
180181
181182 return f'[{ compiler } ]'
182183
@@ -208,7 +209,7 @@ def main():
208209
209210 if free_threading is None :
210211 # Get Py_GIL_DISABLED macro from pyconfig.h
211- free_threading = get_gil_disable ()
212+ free_threading = get_gil_disabled ()
212213
213214 if free_threading :
214215 version = f"{ PY_VERSION } free-threading build ({ build_info } ) { compiler } "
0 commit comments