annotate Tools/scripts/patchcheck.py @ 66382:ada67de64919

Fix resource warning from patchcheck.py
author Éric Araujo <merwok@netwok.org>
date Mon, 22 Nov 2010 03:13:47 +0000
parents 2e19d1f4b612
children 3c9232a684ae
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)
66382
ada67de64919 Fix resource warning from patchcheck.py
Éric Araujo <merwok@netwok.org>
parents: 65570
diff changeset
48 try:
ada67de64919 Fix resource warning from patchcheck.py
Éric Araujo <merwok@netwok.org>
parents: 65570
diff changeset
49 st.wait()
ada67de64919 Fix resource warning from patchcheck.py
Éric Araujo <merwok@netwok.org>
parents: 65570
diff changeset
50 if vcs == 'hg':
ada67de64919 Fix resource warning from patchcheck.py
Éric Araujo <merwok@netwok.org>
parents: 65570
diff changeset
51 return [x.decode().rstrip() for x in st.stdout]
ada67de64919 Fix resource warning from patchcheck.py
Éric Araujo <merwok@netwok.org>
parents: 65570
diff changeset
52 else:
ada67de64919 Fix resource warning from patchcheck.py
Éric Araujo <merwok@netwok.org>
parents: 65570
diff changeset
53 output = (x.decode().rstrip().rsplit(None, 1)[-1]
ada67de64919 Fix resource warning from patchcheck.py
Éric Araujo <merwok@netwok.org>
parents: 65570
diff changeset
54 for x in st.stdout if x[0] in b'AM')
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
55 return set(path for path in output if os.path.isfile(path))
66382
ada67de64919 Fix resource warning from patchcheck.py
Éric Araujo <merwok@netwok.org>
parents: 65570
diff changeset
56 finally:
ada67de64919 Fix resource warning from patchcheck.py
Éric Araujo <merwok@netwok.org>
parents: 65570
diff changeset
57 st.stdout.close()
63872
5ae390ac6c61 Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 62798
diff changeset
58
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
59
62798
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
60 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
61 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
62 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
63 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
64 else:
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
65 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
66 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
67 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
68 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
69
63872
5ae390ac6c61 Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 62798
diff changeset
70
62798
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
71 @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
72 def normalize_whitespace(file_paths):
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
73 """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
74 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
75 fixed = []
7ffd2a44942c Do some basic refactoring. Along the way also list what files had their
Brett Cannon <bcannon@gmail.com>
parents: 50812
diff changeset
76 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
77 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
78 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
79 return fixed
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
80
63872
5ae390ac6c61 Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 62798
diff changeset
81
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
82 @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
83 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
84 """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
85 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
86 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
87 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
88 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
89 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
90 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
91 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
92 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
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
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 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
96
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 @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
98 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
99 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
100 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
101 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
102 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
103 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
104 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
105 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
106 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
107 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
108 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
109 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
110 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
111 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
112 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
113
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
114
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
115 @status("Docs modified", modal=True)
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
116 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
117 """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
118 return bool(file_paths)
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
119
63872
5ae390ac6c61 Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 62798
diff changeset
120
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
121 @status("Misc/ACKS updated", modal=True)
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
122 def credit_given(file_paths):
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
123 """Check if Misc/ACKS has been changed."""
50812
a04b1c7167ba Merged revisions 68630 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 45883
diff changeset
124 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
125
63872
5ae390ac6c61 Clean up syntax for some scripts.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 62798
diff changeset
126
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
127 @status("Misc/NEWS updated", modal=True)
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
128 def reported_news(file_paths):
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
129 """Check if Misc/NEWS has been changed."""
50812
a04b1c7167ba Merged revisions 68630 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 45883
diff changeset
130 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
131
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
132
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
133 def main():
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
134 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
135 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
136 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
137 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
138 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
139 # 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
140 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
141 # 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
142 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
143 # 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
144 normalize_docs_whitespace(doc_files)
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
145 # 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
146 docs_modified(doc_files)
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
147 # 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
148 credit_given(special_files)
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
149 # 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
150 reported_news(special_files)
45865
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
151
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
152 # Test suite run and passed.
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
153 print()
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
154 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
155
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
156
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
157 if __name__ == '__main__':
e0e8bef0d5ec Merged revisions 61520,61523-61528,61532 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
diff changeset
158 main()