@@ -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 :
@@ -170,9 +171,9 @@ def report_modified_files(file_paths):
170
171
if count == 0 :
171
172
return n_files_str (count )
172
173
else :
173
- lines = ["{}:" . format ( n_files_str (count )) ]
174
+ lines = [f" { n_files_str (count )} :" ]
174
175
for path in file_paths :
175
- lines .append (" {}" . format ( path ) )
176
+ lines .append (f " { path } " )
176
177
return "\n " .join (lines )
177
178
178
179
@@ -199,27 +200,6 @@ def normalize_c_whitespace(file_paths):
199
200
return fixed
200
201
201
202
202
- ws_re = re .compile (br'\s+(\r?\n)$' )
203
-
204
- @status ("Fixing docs whitespace" , info = report_modified_files )
205
- def normalize_docs_whitespace (file_paths ):
206
- fixed = []
207
- for path in file_paths :
208
- abspath = os .path .join (SRCDIR , path )
209
- try :
210
- with open (abspath , 'rb' ) as f :
211
- lines = f .readlines ()
212
- new_lines = [ws_re .sub (br'\1' , line ) for line in lines ]
213
- if new_lines != lines :
214
- shutil .copyfile (abspath , abspath + '.bak' )
215
- with open (abspath , 'wb' ) as f :
216
- f .writelines (new_lines )
217
- fixed .append (path )
218
- except Exception as err :
219
- print ('Cannot fix %s: %s' % (path , err ))
220
- return fixed
221
-
222
-
223
203
@status ("Docs modified" , modal = True )
224
204
def docs_modified (file_paths ):
225
205
"""Report if any file in the Doc directory has been changed."""
@@ -238,6 +218,7 @@ def reported_news(file_paths):
238
218
return any (p .startswith (os .path .join ('Misc' , 'NEWS.d' , 'next' ))
239
219
for p in file_paths )
240
220
221
+
241
222
@status ("configure regenerated" , modal = True , info = str )
242
223
def regenerated_configure (file_paths ):
243
224
"""Check if configure has been regenerated."""
@@ -246,6 +227,7 @@ def regenerated_configure(file_paths):
246
227
else :
247
228
return "not needed"
248
229
230
+
249
231
@status ("pyconfig.h.in regenerated" , modal = True , info = str )
250
232
def regenerated_pyconfig_h_in (file_paths ):
251
233
"""Check if pyconfig.h.in has been regenerated."""
@@ -254,6 +236,7 @@ def regenerated_pyconfig_h_in(file_paths):
254
236
else :
255
237
return "not needed"
256
238
239
+
257
240
def ci (pull_request ):
258
241
if pull_request == 'false' :
259
242
print ('Not a pull request; skipping' )
@@ -262,19 +245,18 @@ def ci(pull_request):
262
245
file_paths = changed_files (base_branch )
263
246
python_files = [fn for fn in file_paths if fn .endswith ('.py' )]
264
247
c_files = [fn for fn in file_paths if fn .endswith (('.c' , '.h' ))]
265
- doc_files = [fn for fn in file_paths if fn .startswith ('Doc' ) and
266
- fn .endswith (('.rst' , '.inc' ))]
267
248
fixed = []
268
249
fixed .extend (normalize_whitespace (python_files ))
269
250
fixed .extend (normalize_c_whitespace (c_files ))
270
- fixed .extend (normalize_docs_whitespace (doc_files ))
271
251
if not fixed :
272
252
print ('No whitespace issues found' )
273
253
else :
274
- print (f'Please fix the { len (fixed )} file(s) with whitespace issues' )
275
- print ('(on UNIX you can run `make patchcheck` to make the fixes)' )
254
+ count = len (fixed )
255
+ print (f'Please fix the { n_files_str (count )} with whitespace issues' )
256
+ print ('(on Unix you can run `make patchcheck` to make the fixes)' )
276
257
sys .exit (1 )
277
258
259
+
278
260
def main ():
279
261
base_branch = get_base_branch ()
280
262
file_paths = changed_files (base_branch )
@@ -287,8 +269,6 @@ def main():
287
269
normalize_whitespace (python_files )
288
270
# C rules enforcement.
289
271
normalize_c_whitespace (c_files )
290
- # Doc whitespace enforcement.
291
- normalize_docs_whitespace (doc_files )
292
272
# Docs updated.
293
273
docs_modified (doc_files )
294
274
# Misc/ACKS changed.
0 commit comments