55import reindent
66
77
8+ def n_files_str (count ):
9+ """Return 'N file(s)' with the proper plurality on 'file'."""
10+ return "{} file{}" .format (count , "s" if count != 1 else "" )
11+
812def status (message , modal = False , info = None ):
913 """Decorator to output status info to stdout."""
1014 def decorated_fxn (fxn ):
@@ -26,7 +30,7 @@ def call_fxn(*args, **kwargs):
2630 return decorated_fxn
2731
2832@status ("Getting the list of files that have been added/changed" ,
29- info = lambda x : "%s files" % len (x ))
33+ info = lambda x : n_files_str ( len (x ) ))
3034def changed_files ():
3135 """Run ``svn status`` and return a set of files that have been
3236 changed/added."""
@@ -44,20 +48,30 @@ def changed_files():
4448 files .add (path )
4549 return files
4650
47- @status ("Fixing whitespace" , info = lambda x : "%s files" % x )
51+ def report_modified_files (file_paths ):
52+ count = len (file_paths )
53+ if count == 0 :
54+ return n_files_str (count )
55+ else :
56+ lines = ["{}:" .format (n_files_str (count ))]
57+ for path in file_paths :
58+ lines .append (" {}" .format (path ))
59+ return "\n " .join (lines )
60+
61+ @status ("Fixing whitespace" , info = report_modified_files )
4862def normalize_whitespace (file_paths ):
4963 """Make sure that the whitespace for .py files have been normalized."""
5064 reindent .makebackup = False # No need to create backups.
51- result = list (map (reindent .check , (x for x in file_paths if x .endswith ('.py' ))))
52- return sum (result )
65+ fixed = []
66+ for path in (x for x in file_paths if x .endswith ('.py' )):
67+ if reindent .check (path ):
68+ fixed .append (path )
69+ return fixed
5370
5471@status ("Docs modified" , modal = True )
5572def docs_modified (file_paths ):
56- """Report if any files in the Docs directory."""
57- for path in file_paths :
58- if path .startswith ("Doc" ):
59- return True
60- return False
73+ """Report if any file in the Doc directory has been changed."""
74+ return bool (file_paths )
6175
6276@status ("Misc/ACKS updated" , modal = True )
6377def credit_given (file_paths ):
@@ -72,14 +86,18 @@ def reported_news(file_paths):
7286
7387def main ():
7488 file_paths = changed_files ()
75- # PEP 7/8 verification.
76- normalize_whitespace (file_paths )
89+ python_files = [fn for fn in file_paths if fn .endswith ('.py' )]
90+ c_files = [fn for fn in file_paths if fn .endswith (('.c' , '.h' ))]
91+ docs = [fn for fn in file_paths if fn .startswith ('Doc' )]
92+ special_files = {'Misc/ACKS' , 'Misc/NEWS' } & set (file_paths )
93+ # PEP 8 whitespace rules enforcement.
94+ normalize_whitespace (python_files )
7795 # Docs updated.
78- docs_modified (file_paths )
96+ docs_modified (docs )
7997 # Misc/ACKS changed.
80- credit_given (file_paths )
98+ credit_given (special_files )
8199 # Misc/NEWS changed.
82- reported_news (file_paths )
100+ reported_news (special_files )
83101
84102 # Test suite run and passed.
85103 print ()
0 commit comments