@@ -30,7 +30,8 @@ def get_python_source_dir():
30
30
31
31
def n_files_str (count ):
32
32
"""Return 'N file(s)' with the proper plurality on 'file'."""
33
- return "{} file{}" .format (count , "s" if count != 1 else "" )
33
+ s = "s" if count != 1 else ""
34
+ return f"{ count } file{ s } "
34
35
35
36
36
37
def status (message , modal = False , info = None ):
@@ -84,7 +85,7 @@ def get_git_remote_default_branch(remote_name):
84
85
85
86
It is typically called 'main', but may differ
86
87
"""
87
- cmd = "git remote show {}" . format ( remote_name ) .split ()
88
+ cmd = f "git remote show { remote_name } " .split ()
88
89
env = os .environ .copy ()
89
90
env ['LANG' ] = 'C'
90
91
try :
@@ -171,9 +172,9 @@ def report_modified_files(file_paths):
171
172
if count == 0 :
172
173
return n_files_str (count )
173
174
else :
174
- lines = ["{}:" . format ( n_files_str (count )) ]
175
+ lines = [f" { n_files_str (count )} :" ]
175
176
for path in file_paths :
176
- lines .append (" {}" . format ( path ) )
177
+ lines .append (f " { path } " )
177
178
return "\n " .join (lines )
178
179
179
180
@@ -212,27 +213,6 @@ def normalize_c_whitespace(file_paths):
212
213
return fixed
213
214
214
215
215
- ws_re = re .compile (br'\s+(\r?\n)$' )
216
-
217
- @status ("Fixing docs whitespace" , info = report_modified_files )
218
- def normalize_docs_whitespace (file_paths ):
219
- fixed = []
220
- for path in file_paths :
221
- abspath = os .path .join (SRCDIR , path )
222
- try :
223
- with open (abspath , 'rb' ) as f :
224
- lines = f .readlines ()
225
- new_lines = [ws_re .sub (br'\1' , line ) for line in lines ]
226
- if new_lines != lines :
227
- shutil .copyfile (abspath , abspath + '.bak' )
228
- with open (abspath , 'wb' ) as f :
229
- f .writelines (new_lines )
230
- fixed .append (path )
231
- except Exception as err :
232
- print ('Cannot fix %s: %s' % (path , err ))
233
- return fixed
234
-
235
-
236
216
@status ("Docs modified" , modal = True )
237
217
def docs_modified (file_paths ):
238
218
"""Report if any file in the Doc directory has been changed."""
@@ -251,6 +231,7 @@ def reported_news(file_paths):
251
231
return any (p .startswith (os .path .join ('Misc' , 'NEWS.d' , 'next' ))
252
232
for p in file_paths )
253
233
234
+
254
235
@status ("configure regenerated" , modal = True , info = str )
255
236
def regenerated_configure (file_paths ):
256
237
"""Check if configure has been regenerated."""
@@ -259,6 +240,7 @@ def regenerated_configure(file_paths):
259
240
else :
260
241
return "not needed"
261
242
243
+
262
244
@status ("pyconfig.h.in regenerated" , modal = True , info = str )
263
245
def regenerated_pyconfig_h_in (file_paths ):
264
246
"""Check if pyconfig.h.in has been regenerated."""
@@ -267,6 +249,7 @@ def regenerated_pyconfig_h_in(file_paths):
267
249
else :
268
250
return "not needed"
269
251
252
+
270
253
def ci (pull_request ):
271
254
if pull_request == 'false' :
272
255
print ('Not a pull request; skipping' )
@@ -275,19 +258,18 @@ def ci(pull_request):
275
258
file_paths = changed_files (base_branch )
276
259
python_files = [fn for fn in file_paths if fn .endswith ('.py' )]
277
260
c_files = [fn for fn in file_paths if fn .endswith (('.c' , '.h' ))]
278
- doc_files = [fn for fn in file_paths if fn .startswith ('Doc' ) and
279
- fn .endswith (('.rst' , '.inc' ))]
280
261
fixed = []
281
262
fixed .extend (normalize_whitespace (python_files ))
282
263
fixed .extend (normalize_c_whitespace (c_files ))
283
- fixed .extend (normalize_docs_whitespace (doc_files ))
284
264
if not fixed :
285
265
print ('No whitespace issues found' )
286
266
else :
287
- print (f'Please fix the { len (fixed )} file(s) with whitespace issues' )
288
- print ('(on UNIX you can run `make patchcheck` to make the fixes)' )
267
+ count = len (fixed )
268
+ print (f'Please fix the { n_files_str (count )} with whitespace issues' )
269
+ print ('(on Unix you can run `make patchcheck` to make the fixes)' )
289
270
sys .exit (1 )
290
271
272
+
291
273
def main ():
292
274
base_branch = get_base_branch ()
293
275
file_paths = changed_files (base_branch )
@@ -300,8 +282,6 @@ def main():
300
282
normalize_whitespace (python_files )
301
283
# C rules enforcement.
302
284
normalize_c_whitespace (c_files )
303
- # Doc whitespace enforcement.
304
- normalize_docs_whitespace (doc_files )
305
285
# Docs updated.
306
286
docs_modified (doc_files )
307
287
# Misc/ACKS changed.
0 commit comments