annotate Tools/scripts/patchcheck.py @ 65589:46bbbdcd777f

Refactor interesting use of try-finally.
author Georg Brandl <georg@python.org>
date Fri, 22 Oct 2010 06:35:59 +0000
parents 2e19d1f4b612
children ada67de64919
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
65570
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
1 import re
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
2 import sys
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
3 import shutil
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
4 import os.path
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
5 import subprocess
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
6
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
7 import reindent
65570
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
8 import untabify
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
9
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
10
62798
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
11 def n_files_str(count):
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
12 """Return 'N file(s)' with the proper plurality on 'file'."""
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
13 return "{} file{}".format(count, "s" if count != 1 else "")
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
14
63872
5ae390ac6c61 Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 62798
diff changeset
15
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
16 def status(message, modal=False, info=None):
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
17 """Decorator to output status info to stdout."""
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
18 def decorated_fxn(fxn):
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
19 def call_fxn(*args, **kwargs):
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
20 sys.stdout.write(message + ' ... ')
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
21 sys.stdout.flush()
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
22 result = fxn(*args, **kwargs)
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
23 if not modal and not info:
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
24 print("done")
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
25 elif info:
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
26 print(info(result))
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
27 else:
63872
5ae390ac6c61 Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 62798
diff changeset
28 print("yes" if result else "NO")
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
29 return result
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
30 return call_fxn
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
31 return decorated_fxn
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
32
63872
5ae390ac6c61 Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 62798
diff changeset
33
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
34 @status("Getting the list of files that have been added/changed",
65570
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
35 info=lambda x: n_files_str(len(x)))
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
36 def changed_files():
65570
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
37 """Get the list of changed or added files from the VCS."""
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
38 if os.path.isdir('.hg'):
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
39 vcs = 'hg'
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
40 cmd = 'hg status --added --modified --no-status'
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
41 elif os.path.isdir('.svn'):
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
42 vcs = 'svn'
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
43 cmd = 'svn status --quiet --non-interactive --ignore-externals'
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
44 else:
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
45 sys.exit('need a checkout to get modified files')
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
46
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
47 st = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
48 st.wait()
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
49 if vcs == 'hg':
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
50 return [x.decode().rstrip() for x in st.stdout]
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
51 else:
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
52 output = (x.decode().rstrip().rsplit(None, 1)[-1]
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
53 for x in st.stdout if x[0] in b'AM')
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
54 return set(path for path in output if os.path.isfile(path))
63872
5ae390ac6c61 Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 62798
diff changeset
55
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
56
62798
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
57 def report_modified_files(file_paths):
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
58 count = len(file_paths)
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
59 if count == 0:
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
60 return n_files_str(count)
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
61 else:
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
62 lines = ["{}:".format(n_files_str(count))]
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
63 for path in file_paths:
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
64 lines.append(" {}".format(path))
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
65 return "\n".join(lines)
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
66
63872
5ae390ac6c61 Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 62798
diff changeset
67
62798
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
68 @status("Fixing whitespace", info=report_modified_files)
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
69 def normalize_whitespace(file_paths):
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
70 """Make sure that the whitespace for .py files have been normalized."""
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
71 reindent.makebackup = False # No need to create backups.
62798
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
72 fixed = []
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
73 for path in (x for x in file_paths if x.endswith('.py')):
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
74 if reindent.check(path):
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
75 fixed.append(path)
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
76 return fixed
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
77
63872
5ae390ac6c61 Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 62798
diff changeset
78
65570
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
79 @status("Fixing C file whitespace", info=report_modified_files)
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
80 def normalize_c_whitespace(file_paths):
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
81 """Report if any C files """
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
82 fixed = []
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
83 for path in file_paths:
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
84 with open(path, 'r') as f:
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
85 if '\t' not in f.read():
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
86 continue
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
87 untabify.process(path, 8, verbose=False)
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
88 fixed.append(path)
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
89 return fixed
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
90
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
91
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
92 ws_re = re.compile(br'\s+(\r?\n)$')
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
93
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
94 @status("Fixing docs whitespace", info=report_modified_files)
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
95 def normalize_docs_whitespace(file_paths):
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
96 fixed = []
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
97 for path in file_paths:
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
98 try:
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
99 with open(path, 'rb') as f:
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
100 lines = f.readlines()
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
101 new_lines = [ws_re.sub(br'\1', line) for line in lines]
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
102 if new_lines != lines:
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
103 shutil.copyfile(path, path + '.bak')
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
104 with open(path, 'wb') as f:
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
105 f.writelines(new_lines)
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
106 fixed.append(path)
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
107 except Exception as err:
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
108 print('Cannot fix %s: %s' % (path, err))
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
109 return fixed
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
110
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
111
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
112 @status("Docs modified", modal=True)
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
113 def docs_modified(file_paths):
62798
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
114 """Report if any file in the Doc directory has been changed."""
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
115 return bool(file_paths)
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
116
63872
5ae390ac6c61 Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 62798
diff changeset
117
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
118 @status("Misc/ACKS updated", modal=True)
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
119 def credit_given(file_paths):
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
120 """Check if Misc/ACKS has been changed."""
50812
a04b1c7167ba Merged revisions 68630 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 45883
diff changeset
121 return 'Misc/ACKS' in file_paths
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
122
63872
5ae390ac6c61 Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 62798
diff changeset
123
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
124 @status("Misc/NEWS updated", modal=True)
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
125 def reported_news(file_paths):
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
126 """Check if Misc/NEWS has been changed."""
50812
a04b1c7167ba Merged revisions 68630 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 45883
diff changeset
127 return 'Misc/NEWS' in file_paths
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
128
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
129
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
130 def main():
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
131 file_paths = changed_files()
62798
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
132 python_files = [fn for fn in file_paths if fn.endswith('.py')]
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
133 c_files = [fn for fn in file_paths if fn.endswith(('.c', '.h'))]
65570
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
134 doc_files = [fn for fn in file_paths if fn.startswith('Doc')]
62798
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
135 special_files = {'Misc/ACKS', 'Misc/NEWS'} & set(file_paths)
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
136 # PEP 8 whitespace rules enforcement.
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
137 normalize_whitespace(python_files)
65570
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
138 # C rules enforcement.
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
139 normalize_c_whitespace(c_files)
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
140 # Doc whitespace enforcement.
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
141 normalize_docs_whitespace(doc_files)
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
142 # Docs updated.
65570
2e19d1f4b612 #9095, #8912, #8999: add support in patchcheck for Mercurial checkouts, C file reindenting, and docs whitespace fixing.
Georg Brandl <georg@python.org>
parents: 63872
diff changeset
143 docs_modified(doc_files)
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
144 # Misc/ACKS changed.
62798
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
145 credit_given(special_files)
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
146 # Misc/NEWS changed.
62798
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
147 reported_news(special_files)
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
148
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
149 # Test suite run and passed.
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
150 print()
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
151 print("Did you run the test suite?")
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
152
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
153
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
154 if __name__ == '__main__':
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
155 main()