55import subprocess
66import sys
77import sysconfig
8+ import _colorize
89
910ALLOWED_PREFIXES = ('Py' , '_Py' )
1011if sys .platform == 'darwin' :
@@ -43,8 +44,9 @@ def is_local_symbol_type(symtype):
4344 return False
4445
4546
46- def get_exported_symbols (library , dynamic = False ):
47- print (f"Check that { library } only exports symbols starting with Py or _Py" )
47+ def get_exported_symbols (library , dynamic = False , * , colors ):
48+ name , dot , ext = os .path .basename (library ).partition ('.' )
49+ print (f"Check { colors .INTENSE_WHITE } { name } { colors .RESET } { dot } { ext } " )
4850
4951 # Only look at dynamic symbols
5052 args = ['nm' , '--no-sort' ]
@@ -99,12 +101,13 @@ def get_smelly_symbols(stdout, dynamic=False):
99101 return smelly_symbols , python_symbols
100102
101103
102- def check_library (library , dynamic = False ):
103- nm_output = get_exported_symbols (library , dynamic )
104+ def check_library (library , dynamic = False , * , colors ):
105+ nm_output = get_exported_symbols (library , dynamic , colors = colors )
104106 smelly_symbols , python_symbols = get_smelly_symbols (nm_output , dynamic )
105107
106108 if not smelly_symbols :
107- print (f"OK: no smelly symbol found ({ len (python_symbols )} Python symbols)" )
109+ print (f"{ colors .GREEN } OK{ colors .RESET } :" ,
110+ f"no smelly symbol found ({ len (python_symbols )} Python symbols)" )
108111 return 0
109112
110113 print ()
@@ -113,11 +116,12 @@ def check_library(library, dynamic=False):
113116 print (f"Smelly symbol: { symbol } " )
114117
115118 print ()
116- print (f"ERROR: Found { len (smelly_symbols )} smelly symbols!" )
119+ print (f"{ colors .RED } ERROR{ colors .RESET } :" ,
120+ f"Found { len (smelly_symbols )} smelly symbols!" )
117121 return len (smelly_symbols )
118122
119123
120- def check_extensions ():
124+ def check_extensions (colors ):
121125 print (__file__ )
122126 # This assumes pybuilddir.txt is in same directory as pyconfig.h.
123127 # In the case of out-of-tree builds, we can't assume pybuilddir.txt is
@@ -144,40 +148,45 @@ def check_extensions():
144148
145149 print ()
146150 filename = os .path .join (builddir , name )
147- nsymbol += check_library (filename , dynamic = True )
151+ nsymbol += check_library (filename , dynamic = True , colors = colors )
148152
149153 return nsymbol
150154
151155
152156def main ():
157+ colors = _colorize .get_colors ()
158+
153159 nsymbol = 0
154160
155161 # static library
156162 LIBRARY = sysconfig .get_config_var ('LIBRARY' )
157163 if not LIBRARY :
158164 raise Exception ("failed to get LIBRARY variable from sysconfig" )
159165 if os .path .exists (LIBRARY ):
160- nsymbol += check_library (LIBRARY )
166+ nsymbol += check_library (LIBRARY , colors = colors )
161167
162168 # dynamic library
163169 LDLIBRARY = sysconfig .get_config_var ('LDLIBRARY' )
164170 if not LDLIBRARY :
165171 raise Exception ("failed to get LDLIBRARY variable from sysconfig" )
166172 if LDLIBRARY != LIBRARY :
167173 print ()
168- nsymbol += check_library (LDLIBRARY , dynamic = True )
174+ nsymbol += check_library (LDLIBRARY , dynamic = True , colors = colors )
169175
170176 # Check extension modules like _ssl.cpython-310d-x86_64-linux-gnu.so
171- nsymbol += check_extensions ()
177+ nsymbol += check_extensions (colors = colors )
172178
173179 if nsymbol :
174180 print ()
175- print (f"ERROR: Found { nsymbol } smelly symbols in total!" )
181+ print (f"{ colors .RED } ERROR{ colors .RESET } :" ,
182+ f"Found { nsymbol } smelly symbols in total!" )
176183 sys .exit (1 )
177184
178185 print ()
179- print (f"OK: all exported symbols of all libraries "
180- f"are prefixed with { ' or ' .join (map (repr , ALLOWED_PREFIXES ))} " )
186+ print (f"{ colors .GREEN } OK{ colors .RESET } :" ,
187+ f"all exported symbols of all libraries" ,
188+ f"are prefixed with { ' or ' .join (map (repr , ALLOWED_PREFIXES ))} " ,
189+ f"or are covered by exceptions" )
181190
182191
183192if __name__ == "__main__" :
0 commit comments