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

Side by Side Diff: presubmit_support.py

Issue 74163002: Allow PRESUBMIT.py files to have old and new-style trybot specifications (as long as each file is c… (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Address maruel's comments. Created 7 years, 1 month 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
« no previous file with comments | « no previous file | trychange.py » ('j') | trychange.py » ('J')
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) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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.7.0' 9 __version__ = '1.7.0'
10 10
(...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 """ 1074 """
1075 presubmit_files = ListRelevantPresubmitFiles(changed_files, repository_root) 1075 presubmit_files = ListRelevantPresubmitFiles(changed_files, repository_root)
1076 if not presubmit_files and verbose: 1076 if not presubmit_files and verbose:
1077 output_stream.write("Warning, no presubmit.py found.\n") 1077 output_stream.write("Warning, no presubmit.py found.\n")
1078 results = [] 1078 results = []
1079 executer = GetTrySlavesExecuter() 1079 executer = GetTrySlavesExecuter()
1080 if default_presubmit: 1080 if default_presubmit:
1081 if verbose: 1081 if verbose:
1082 output_stream.write("Running default presubmit script.\n") 1082 output_stream.write("Running default presubmit script.\n")
1083 fake_path = os.path.join(repository_root, 'PRESUBMIT.py') 1083 fake_path = os.path.join(repository_root, 'PRESUBMIT.py')
1084 results += executer.ExecPresubmitScript( 1084 result = executer.ExecPresubmitScript(
1085 default_presubmit, fake_path, project, change) 1085 default_presubmit, fake_path, project, change)
1086 # Ensure it's either all old-style or new-style.
1087 if (all(isinstance(i, tuple) for i in result) or
1088 all(isinstance(i, basestring) for i in result)):
1089 results.extend(result)
1090 else:
1091 raise ValueError('PRESUBMIT.py returned invalid trybot specification!')
1086 for filename in presubmit_files: 1092 for filename in presubmit_files:
1087 filename = os.path.abspath(filename) 1093 filename = os.path.abspath(filename)
1088 if verbose: 1094 if verbose:
1089 output_stream.write("Running %s\n" % filename) 1095 output_stream.write("Running %s\n" % filename)
1090 # Accept CRLF presubmit script. 1096 # Accept CRLF presubmit script.
1091 presubmit_script = gclient_utils.FileRead(filename, 'rU') 1097 presubmit_script = gclient_utils.FileRead(filename, 'rU')
1092 results += executer.ExecPresubmitScript( 1098 result = executer.ExecPresubmitScript(
1093 presubmit_script, filename, project, change) 1099 presubmit_script, filename, project, change)
1100 if (all(isinstance(i, tuple) for i in result) or
1101 all(isinstance(i, basestring) for i in result)):
1102 results.extend(result)
1103 else:
1104 raise ValueError('%s returned invalid trybot specification!' % filename)
1094 1105
Isaac (away) 2013/12/04 03:47:43 if you make results a list of lists instead of fla
1095 if all(isinstance(i, tuple) for i in results): 1106
1096 # New-style [('bot', set(['tests']))] format. 1107 slave_dict = {}
1097 slave_dict = {} 1108 old_style = filter(lambda x: isinstance(x, basestring), results)
1098 for result in results: 1109 new_style = filter(lambda x: isinstance(x, tuple), results)
1099 slave_dict.setdefault(result[0], set()).update(result[1]) 1110
1100 slaves = list(slave_dict.iteritems()) 1111 for result in new_style:
1101 elif all(isinstance(i, basestring) for i in results): 1112 slave_dict.setdefault(result[0], set()).update(result[1])
Isaac (away) 2013/12/04 03:47:43 now that we're on 2.7, how about collections.defau
ghost stip (do not use) 2013/12/18 00:43:08 we're not yet on 2.7, see crbug.com/328453. filte
1102 # Old-style ['bot'] format. 1113 slaves = list(slave_dict.iteritems())
M-A Ruel 2013/12/04 01:02:31 slaves = slave_dict.items()
ghost stip (do not use) 2013/12/18 00:43:08 not sure if that's what we want, we want (bot, tes
M-A Ruel 2013/12/18 00:52:43 http://docs.python.org/2/library/stdtypes.html#dic
1103 slaves = list(set(results)) 1114
1104 else: 1115 slaves += list(set(old_style))
M-A Ruel 2013/12/04 01:02:31 slaves.extend(set(old_style))
1105 raise ValueError('PRESUBMIT.py returned invalid trybot specification!')
1106 1116
1107 if slaves and verbose: 1117 if slaves and verbose:
1108 output_stream.write(', '.join(slaves)) 1118 output_stream.write(', '.join((str(x) for x in slaves)))
1109 output_stream.write('\n') 1119 output_stream.write('\n')
1110 return slaves 1120 return slaves
1111 1121
1112 1122
1113 class PresubmitExecuter(object): 1123 class PresubmitExecuter(object):
1114 def __init__(self, change, committing, rietveld_obj, verbose): 1124 def __init__(self, change, committing, rietveld_obj, verbose):
1115 """ 1125 """
1116 Args: 1126 Args:
1117 change: The Change object. 1127 change: The Change object.
1118 committing: True if 'gcl commit' is running, False if 'gcl upload' is. 1128 committing: True if 'gcl commit' is running, False if 'gcl upload' is.
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 except PresubmitFailure, e: 1456 except PresubmitFailure, e:
1447 print >> sys.stderr, e 1457 print >> sys.stderr, e
1448 print >> sys.stderr, 'Maybe your depot_tools is out of date?' 1458 print >> sys.stderr, 'Maybe your depot_tools is out of date?'
1449 print >> sys.stderr, 'If all fails, contact maruel@' 1459 print >> sys.stderr, 'If all fails, contact maruel@'
1450 return 2 1460 return 2
1451 1461
1452 1462
1453 if __name__ == '__main__': 1463 if __name__ == '__main__':
1454 fix_encoding.fix_encoding() 1464 fix_encoding.fix_encoding()
1455 sys.exit(Main(None)) 1465 sys.exit(Main(None))
OLDNEW
« no previous file with comments | « no previous file | trychange.py » ('j') | trychange.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698