Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: presubmit_support.py

Issue 6854022: Inhibit python subprocess from generating .pyc files anymore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Enables directory-specific presubmit checks to run at upload and/or commit. 6 """Enables directory-specific presubmit checks to run at upload and/or commit.
7 """ 7 """
8 8
9 __version__ = '1.6.1' 9 __version__ = '1.6.1'
10 10
(...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 rietveld: rietveld object. 1028 rietveld: rietveld object.
1029 1029
1030 Warning: 1030 Warning:
1031 If may_prompt is true, output_stream SHOULD be sys.stdout and input_stream 1031 If may_prompt is true, output_stream SHOULD be sys.stdout and input_stream
1032 SHOULD be sys.stdin. 1032 SHOULD be sys.stdin.
1033 1033
1034 Return: 1034 Return:
1035 A PresubmitOutput object. Use output.should_continue() to figure out 1035 A PresubmitOutput object. Use output.should_continue() to figure out
1036 if there were errors or warnings and the caller should abort. 1036 if there were errors or warnings and the caller should abort.
1037 """ 1037 """
1038 output = PresubmitOutput(input_stream, output_stream) 1038 old_environ = os.environ
1039 if committing: 1039 try:
1040 output.write("Running presubmit commit checks ...\n") 1040 # Make sure python subprocesses won't generate .pyc files.
1041 else: 1041 os.environ = os.environ.copy()
1042 output.write("Running presubmit upload checks ...\n") 1042 os.environ['PYTHONDONTWRITEBYTECODE'] = '1'
1043 start_time = time.time()
1044 presubmit_files = ListRelevantPresubmitFiles(change.AbsoluteLocalPaths(True),
1045 change.RepositoryRoot())
1046 if not presubmit_files and verbose:
1047 output.write("Warning, no presubmit.py found.\n")
1048 results = []
1049 executer = PresubmitExecuter(change, committing, tbr, rietveld, verbose)
1050 if default_presubmit:
1051 if verbose:
1052 output.write("Running default presubmit script.\n")
1053 fake_path = os.path.join(change.RepositoryRoot(), 'PRESUBMIT.py')
1054 results += executer.ExecPresubmitScript(default_presubmit, fake_path)
1055 for filename in presubmit_files:
1056 filename = os.path.abspath(filename)
1057 if verbose:
1058 output.write("Running %s\n" % filename)
1059 # Accept CRLF presubmit script.
1060 presubmit_script = gclient_utils.FileRead(filename, 'rU')
1061 results += executer.ExecPresubmitScript(presubmit_script, filename)
1062 1043
1063 errors = [] 1044 output = PresubmitOutput(input_stream, output_stream)
1064 notifications = [] 1045 if committing:
1065 warnings = [] 1046 output.write("Running presubmit commit checks ...\n")
1066 for result in results:
1067 if result.fatal:
1068 errors.append(result)
1069 elif result.should_prompt:
1070 warnings.append(result)
1071 else: 1047 else:
1072 notifications.append(result) 1048 output.write("Running presubmit upload checks ...\n")
1049 start_time = time.time()
1050 presubmit_files = ListRelevantPresubmitFiles(
1051 change.AbsoluteLocalPaths(True), change.RepositoryRoot())
1052 if not presubmit_files and verbose:
1053 output.write("Warning, no presubmit.py found.\n")
1054 results = []
1055 executer = PresubmitExecuter(change, committing, tbr, rietveld, verbose)
1056 if default_presubmit:
1057 if verbose:
1058 output.write("Running default presubmit script.\n")
1059 fake_path = os.path.join(change.RepositoryRoot(), 'PRESUBMIT.py')
1060 results += executer.ExecPresubmitScript(default_presubmit, fake_path)
1061 for filename in presubmit_files:
1062 filename = os.path.abspath(filename)
1063 if verbose:
1064 output.write("Running %s\n" % filename)
1065 # Accept CRLF presubmit script.
1066 presubmit_script = gclient_utils.FileRead(filename, 'rU')
1067 results += executer.ExecPresubmitScript(presubmit_script, filename)
1073 1068
1074 output.write('\n') 1069 errors = []
1075 for name, items in (('Messages', notifications), 1070 notifications = []
1076 ('Warnings', warnings), 1071 warnings = []
1077 ('ERRORS', errors)): 1072 for result in results:
1078 if items: 1073 if result.fatal:
1079 output.write('** Presubmit %s **\n' % name) 1074 errors.append(result)
1080 for item in items: 1075 elif result.should_prompt:
1081 item.handle(output) 1076 warnings.append(result)
1082 output.write('\n') 1077 else:
1078 notifications.append(result)
1083 1079
1084 total_time = time.time() - start_time 1080 output.write('\n')
1085 if total_time > 1.0: 1081 for name, items in (('Messages', notifications),
1086 output.write("Presubmit checks took %.1fs to calculate.\n\n" % total_time) 1082 ('Warnings', warnings),
1083 ('ERRORS', errors)):
1084 if items:
1085 output.write('** Presubmit %s **\n' % name)
1086 for item in items:
1087 item.handle(output)
1088 output.write('\n')
1087 1089
1088 if not errors: 1090 total_time = time.time() - start_time
1089 if not warnings: 1091 if total_time > 1.0:
1090 output.write('Presubmit checks passed.\n') 1092 output.write("Presubmit checks took %.1fs to calculate.\n\n" % total_time)
1091 elif may_prompt:
1092 output.prompt_yes_no('There were presubmit warnings. '
1093 'Are you sure you wish to continue? (y/N): ')
1094 else:
1095 output.fail()
1096 1093
1097 global _ASKED_FOR_FEEDBACK 1094 if not errors:
1098 # Ask for feedback one time out of 5. 1095 if not warnings:
1099 if (len(results) and random.randint(0, 4) == 0 and not _ASKED_FOR_FEEDBACK): 1096 output.write('Presubmit checks passed.\n')
1100 output.write("Was the presubmit check useful? Please send feedback " 1097 elif may_prompt:
1101 "& hate mail to maruel@chromium.org!\n") 1098 output.prompt_yes_no('There were presubmit warnings. '
1102 _ASKED_FOR_FEEDBACK = True 1099 'Are you sure you wish to continue? (y/N): ')
1103 return output 1100 else:
1101 output.fail()
1102
1103 global _ASKED_FOR_FEEDBACK
1104 # Ask for feedback one time out of 5.
1105 if (len(results) and random.randint(0, 4) == 0 and not _ASKED_FOR_FEEDBACK):
1106 output.write("Was the presubmit check useful? Please send feedback "
1107 "& hate mail to maruel@chromium.org!\n")
1108 _ASKED_FOR_FEEDBACK = True
1109 return output
1110 finally:
1111 os.environ = old_environ
1104 1112
1105 1113
1106 def ScanSubDirs(mask, recursive): 1114 def ScanSubDirs(mask, recursive):
1107 if not recursive: 1115 if not recursive:
1108 return [x for x in glob.glob(mask) if '.svn' not in x and '.git' not in x] 1116 return [x for x in glob.glob(mask) if '.svn' not in x and '.git' not in x]
1109 else: 1117 else:
1110 results = [] 1118 results = []
1111 for root, dirs, files in os.walk('.'): 1119 for root, dirs, files in os.walk('.'):
1112 if '.svn' in dirs: 1120 if '.svn' in dirs:
1113 dirs.remove('.svn') 1121 dirs.remove('.svn')
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 except PresubmitFailure, e: 1213 except PresubmitFailure, e:
1206 print >> sys.stderr, e 1214 print >> sys.stderr, e
1207 print >> sys.stderr, 'Maybe your depot_tools is out of date?' 1215 print >> sys.stderr, 'Maybe your depot_tools is out of date?'
1208 print >> sys.stderr, 'If all fails, contact maruel@' 1216 print >> sys.stderr, 'If all fails, contact maruel@'
1209 return 2 1217 return 2
1210 1218
1211 1219
1212 if __name__ == '__main__': 1220 if __name__ == '__main__':
1213 fix_encoding.fix_encoding() 1221 fix_encoding.fix_encoding()
1214 sys.exit(Main(None)) 1222 sys.exit(Main(None))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698