annotate Tools/scripts/patchcheck.py @ 49955:878d40468c4e legacy-trunk

Issue #4384: Added logging integration with warnings module using captureWarnings(). This change includes a NullHandler which does nothing; it will be of use to library developers who want to avoid the "No handlers could be found for logger XXX" message which can appear if the library user doesn't configure logging.
author Vinay Sajip <vinay_sajip@yahoo.co.uk>
date Wed, 03 Dec 2008 23:22:58 +0000
parents c424099b4ce4
children 2d453b221bec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
45859
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
1 import os.path
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
2 import subprocess
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
3 import sys
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
4
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
5 import reindent
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
6
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
7
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
8 def status(message, modal=False, info=None):
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
9 """Decorator to output status info to stdout."""
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
10 def decorated_fxn(fxn):
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
11 def call_fxn(*args, **kwargs):
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
12 sys.stdout.write(message + ' ... ')
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
13 sys.stdout.flush()
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
14 result = fxn(*args, **kwargs)
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
15 if not modal and not info:
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
16 print "done"
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
17 elif info:
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
18 print info(result)
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
19 else:
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
20 if result:
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
21 print "yes"
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
22 else:
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
23 print "NO"
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
24 return result
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
25 return call_fxn
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
26 return decorated_fxn
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
27
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
28 @status("Getting the list of files that have been added/changed",
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
29 info=lambda x: "%s files" % len(x))
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
30 def changed_files():
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
31 """Run ``svn status`` and return a set of files that have been
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
32 changed/added."""
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
33 cmd = 'svn status --quiet --non-interactive --ignore-externals'
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
34 svn_st = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
35 svn_st.wait()
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
36 output = [line.strip() for line in svn_st.stdout.readlines()]
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
37 files = set()
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
38 for line in output:
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
39 if not line[0] in ('A', 'M'):
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
40 continue
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
41 line_parts = line.split()
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
42 path = line_parts[-1]
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
43 if os.path.isfile(path):
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
44 files.add(path)
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
45 return files
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
46
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
47 @status("Fixing whitespace", info=lambda x: "%s files" % x)
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
48 def normalize_whitespace(file_paths):
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
49 """Make sure that the whitespace for .py files have been normalized."""
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
50 reindent.makebackup = False # No need to create backups.
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
51 result = map(reindent.check, (x for x in file_paths if x.endswith('.py')))
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
52 return sum(result)
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
53
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
54 @status("Docs modified", modal=True)
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
55 def docs_modified(file_paths):
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
56 """Report if any files in the Docs directory."""
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
57 for path in file_paths:
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
58 if path.startswith("Doc"):
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
59 return True
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
60 return False
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
61
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
62 @status("Misc/ACKS updated", modal=True)
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
63 def credit_given(file_paths):
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
64 """Check if Misc/ACKS has been changed."""
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
65 return True if 'Misc/ACKS' in file_paths else False
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
66
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
67 @status("Misc/NEWS updated", modal=True)
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
68 def reported_news(file_paths):
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
69 """Check if Misc/NEWS has been changed."""
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
70 return True if 'Misc/NEWS' in file_paths else False
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
71
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
72
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
73 def main():
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
74 file_paths = changed_files()
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
75 # PEP 7/8 verification.
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
76 normalize_whitespace(file_paths)
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
77 # Docs updated.
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
78 docs_modified(file_paths)
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
79 # Misc/ACKS changed.
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
80 credit_given(file_paths)
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
81 # Misc/NEWS changed.
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
82 reported_news(file_paths)
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
83
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
84 # Test suite run and passed.
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
85 print
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
86 print "Did you run the test suite?"
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
87
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
88
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
89 if __name__ == '__main__':
c424099b4ce4 Add Tools/scripts/patchcheck.py. Invoked from ``make check``, the script does
Brett Cannon <bcannon@gmail.com>
parents:
diff changeset
90 main()