blob: 544b00eae76a4e3d70d992eb59bf9e673ae35584 [file] [log] [blame]
Christian Heimesada8c3b2008-03-18 18:26:33 +00001import os.path
2import subprocess
3import sys
4
5import reindent
6
7
8def 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
27
28@status("Getting the list of files that have been added/changed",
29 info=lambda x: "%s files" % len(x))
30def 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()
Brett Cannon5396a662008-03-18 21:45:57 +000036 output = [x.decode().rstrip() for x in svn_st.stdout.readlines()]
Christian Heimesada8c3b2008-03-18 18:26:33 +000037 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
46
47@status("Fixing whitespace", info=lambda x: "%s files" % x)
48def 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 = list(map(reindent.check, (x for x in file_paths if x.endswith('.py'))))
52 return sum(result)
53
54@status("Docs modified", modal=True)
55def 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
61
62@status("Misc/ACKS updated", modal=True)
63def credit_given(file_paths):
64 """Check if Misc/ACKS has been changed."""
Benjamin Peterson058e31e2009-01-16 03:54:08 +000065 return 'Misc/ACKS' in file_paths
Christian Heimesada8c3b2008-03-18 18:26:33 +000066
67@status("Misc/NEWS updated", modal=True)
68def reported_news(file_paths):
69 """Check if Misc/NEWS has been changed."""
Benjamin Peterson058e31e2009-01-16 03:54:08 +000070 return 'Misc/NEWS' in file_paths
Christian Heimesada8c3b2008-03-18 18:26:33 +000071
72
73def 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)
83
84 # Test suite run and passed.
85 print()
86 print("Did you run the test suite?")
87
88
89if __name__ == '__main__':
90 main()