Issue #7117, continued: Remove substitution of %g-style formatting for
[python.git] / Tools / scripts / patchcheck.py
blobe194c98cb04b3c84e79e2f9b00b0a1a880fd9773
1 import os.path
2 import subprocess
3 import sys
5 import reindent
8 def status(message, modal=False, info=None):
9 """Decorator to output status info to stdout."""
10 def decorated_fxn(fxn):
11 def call_fxn(*args, **kwargs):
12 sys.stdout.write(message + ' ... ')
13 sys.stdout.flush()
14 result = fxn(*args, **kwargs)
15 if not modal and not info:
16 print "done"
17 elif info:
18 print info(result)
19 else:
20 if result:
21 print "yes"
22 else:
23 print "NO"
24 return result
25 return call_fxn
26 return decorated_fxn
28 @status("Getting the list of files that have been added/changed",
29 info=lambda x: "%s files" % len(x))
30 def changed_files():
31 """Run ``svn status`` and return a set of files that have been
32 changed/added."""
33 cmd = 'svn status --quiet --non-interactive --ignore-externals'
34 svn_st = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
35 svn_st.wait()
36 output = [line.strip() for line in svn_st.stdout.readlines()]
37 files = set()
38 for line in output:
39 if not line[0] in ('A', 'M'):
40 continue
41 line_parts = line.split()
42 path = line_parts[-1]
43 if os.path.isfile(path):
44 files.add(path)
45 return files
47 @status("Fixing whitespace", info=lambda x: "%s files" % x)
48 def normalize_whitespace(file_paths):
49 """Make sure that the whitespace for .py files have been normalized."""
50 reindent.makebackup = False # No need to create backups.
51 result = map(reindent.check, (x for x in file_paths if x.endswith('.py')))
52 return sum(result)
54 @status("Docs modified", modal=True)
55 def 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
62 @status("Misc/ACKS updated", modal=True)
63 def credit_given(file_paths):
64 """Check if Misc/ACKS has been changed."""
65 return 'Misc/ACKS' in file_paths
67 @status("Misc/NEWS updated", modal=True)
68 def reported_news(file_paths):
69 """Check if Misc/NEWS has been changed."""
70 return 'Misc/NEWS' in file_paths
73 def main():
74 file_paths = changed_files()
75 # PEP 7/8 verification.
76 normalize_whitespace(file_paths)
77 # Docs updated.
78 docs_modified(file_paths)
79 # Misc/ACKS changed.
80 credit_given(file_paths)
81 # Misc/NEWS changed.
82 reported_news(file_paths)
84 # Test suite run and passed.
85 print
86 print "Did you run the test suite?"
89 if __name__ == '__main__':
90 main()