Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Generic presubmit checks that can be reused by other presubmit checks.""" | 5 """Generic presubmit checks that can be reused by other presubmit checks.""" |
| 6 | 6 |
| 7 ### Description checks | 7 ### Description checks |
| 8 | 8 |
| 9 def CheckChangeHasTestField(input_api, output_api): | 9 def CheckChangeHasTestField(input_api, output_api): |
| 10 """Requires that the changelist have a TEST= field.""" | 10 """Requires that the changelist have a TEST= field.""" |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 # Discard the output if returncode == 0 | 443 # Discard the output if returncode == 0 |
| 444 if subproc.returncode: | 444 if subproc.returncode: |
| 445 outputs.append('Test \'%s\' failed with code %d\n%s\n%s\n' % ( | 445 outputs.append('Test \'%s\' failed with code %d\n%s\n%s\n' % ( |
| 446 unit_test_name, subproc.returncode, stdoutdata, stderrdata)) | 446 unit_test_name, subproc.returncode, stdoutdata, stderrdata)) |
| 447 if outputs: | 447 if outputs: |
| 448 return [message_type('%d unit tests failed.' % len(outputs), | 448 return [message_type('%d unit tests failed.' % len(outputs), |
| 449 long_text='\n'.join(outputs))] | 449 long_text='\n'.join(outputs))] |
| 450 return [] | 450 return [] |
| 451 | 451 |
| 452 | 452 |
| 453 def RunPylint(input_api, output_api, source_file_filter=None): | |
| 454 """Run pylint on python files.""" | |
| 455 import warnings | |
| 456 # On certain pylint/python version combination, running pylint throws a lot of | |
| 457 # warnings messages. | |
|
Evan Martin
2010/12/13 20:54:10
typo: warning (no s)
| |
| 458 warnings.filterwarnings('ignore', category=DeprecationWarning) | |
| 459 try: | |
| 460 if not source_file_filter: | |
| 461 source_file_filter = lambda f: f.LocalPath().endswith('.py') | |
| 462 files = [f.LocalPath() | |
| 463 for f in input_api.AffectedSourceFiles(source_file_filter)] | |
| 464 else: | |
| 465 files = [f.LocalPath() | |
| 466 for f in input_api.AffectedFiles() | |
| 467 if source_file_filter(f)] | |
|
Evan Martin
2010/12/13 20:54:10
Do you know why this can't share code with the abo
| |
| 468 try: | |
| 469 from pylint import lint | |
| 470 if lint.Run(sorted(files)): | |
| 471 return [output_api.PresubmitPromptWarning('Fix pylint errors first.')] | |
| 472 return [] | |
| 473 except ImportError: | |
| 474 if input_api.platform == 'win32': | |
| 475 return [output_api.PresubmitNotifyResult( | |
| 476 'Warning: Can\'t run pylint because it is not installed. Please ' | |
| 477 'install manually\n' | |
| 478 'Cannot do static analysis of python files.')] | |
| 479 return [output_api.PresubmitError( | |
| 480 'Please install pylint with "sudo apt-get install python-setuptools; ' | |
| 481 'sudo easy_install pylint"\n' | |
| 482 'Cannot do static analysis of python files.')] | |
| 483 finally: | |
| 484 warnings.filterwarnings('default', category=DeprecationWarning) | |
| 485 | |
| 486 | |
| 453 def CheckRietveldTryJobExecution(input_api, output_api, host_url, platforms, | 487 def CheckRietveldTryJobExecution(input_api, output_api, host_url, platforms, |
| 454 owner): | 488 owner): |
| 455 if not input_api.is_committing: | 489 if not input_api.is_committing: |
| 456 return [] | 490 return [] |
| 457 if not input_api.change.issue or not input_api.change.patchset: | 491 if not input_api.change.issue or not input_api.change.patchset: |
| 458 return [] | 492 return [] |
| 459 url = '%s/%d/get_build_results/%d' % ( | 493 url = '%s/%d/get_build_results/%d' % ( |
| 460 host_url, input_api.change.issue, input_api.change.patchset) | 494 host_url, input_api.change.issue, input_api.change.patchset) |
| 461 try: | 495 try: |
| 462 connection = input_api.urllib2.urlopen(url) | 496 connection = input_api.urllib2.urlopen(url) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 pending_builds_len = len(builder.get('pending_builds', [])) | 560 pending_builds_len = len(builder.get('pending_builds', [])) |
| 527 if pending_builds_len > max_pendings: | 561 if pending_builds_len > max_pendings: |
| 528 out.append('%s has %d build(s) pending' % | 562 out.append('%s has %d build(s) pending' % |
| 529 (builder_name, pending_builds_len)) | 563 (builder_name, pending_builds_len)) |
| 530 if out: | 564 if out: |
| 531 return [output_api.PresubmitPromptWarning( | 565 return [output_api.PresubmitPromptWarning( |
| 532 'Build(s) pending. It is suggested to wait that no more than %d ' | 566 'Build(s) pending. It is suggested to wait that no more than %d ' |
| 533 'builds are pending.' % max_pendings, | 567 'builds are pending.' % max_pendings, |
| 534 long_text='\n'.join(out))] | 568 long_text='\n'.join(out))] |
| 535 return [] | 569 return [] |
| OLD | NEW |