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 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 dirnames.remove(item) | 487 dirnames.remove(item) |
488 for item in filenames: | 488 for item in filenames: |
489 filepath = input_api.os_path.join(dirpath, item) | 489 filepath = input_api.os_path.join(dirpath, item) |
490 if Find(filepath, white_list) and not Find(filepath, black_list): | 490 if Find(filepath, white_list) and not Find(filepath, black_list): |
491 files.append(filepath) | 491 files.append(filepath) |
492 | 492 |
493 # Now that at least one python file was modified and all the python files | 493 # Now that at least one python file was modified and all the python files |
494 # were listed, try to run pylint. | 494 # were listed, try to run pylint. |
495 try: | 495 try: |
496 from pylint import lint | 496 from pylint import lint |
497 if lint.Run(sorted(files)): | 497 result = lint.Run(sorted(files)) |
498 return [output_api.PresubmitPromptWarning('Fix pylint errors first.')] | 498 except SystemExit, e: |
499 return [] | 499 # pylint has the bad habit of calling sys.exit(), trap it here. |
| 500 result = e.code |
500 except ImportError: | 501 except ImportError: |
501 if input_api.platform == 'win32': | 502 if input_api.platform == 'win32': |
502 return [output_api.PresubmitNotifyResult( | 503 return [output_api.PresubmitNotifyResult( |
503 'Warning: Can\'t run pylint because it is not installed. Please ' | 504 'Warning: Can\'t run pylint because it is not installed. Please ' |
504 'install manually\n' | 505 'install manually\n' |
505 'Cannot do static analysis of python files.')] | 506 'Cannot do static analysis of python files.')] |
506 return [output_api.PresubmitError( | 507 return [output_api.PresubmitError( |
507 'Please install pylint with "sudo apt-get install python-setuptools; ' | 508 'Please install pylint with "sudo apt-get install python-setuptools; ' |
508 'sudo easy_install pylint"\n' | 509 'sudo easy_install pylint"\n' |
509 'Cannot do static analysis of python files.')] | 510 'Cannot do static analysis of python files.')] |
| 511 if result: |
| 512 return [output_api.PresubmitPromptWarning('Fix pylint errors first.')] |
| 513 return [] |
510 finally: | 514 finally: |
511 warnings.filterwarnings('default', category=DeprecationWarning) | 515 warnings.filterwarnings('default', category=DeprecationWarning) |
512 | 516 |
513 | 517 |
514 def CheckRietveldTryJobExecution(input_api, output_api, host_url, platforms, | 518 def CheckRietveldTryJobExecution(input_api, output_api, host_url, platforms, |
515 owner): | 519 owner): |
516 if not input_api.is_committing: | 520 if not input_api.is_committing: |
517 return [] | 521 return [] |
518 if not input_api.change.issue or not input_api.change.patchset: | 522 if not input_api.change.issue or not input_api.change.patchset: |
519 return [] | 523 return [] |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 pending_builds_len = len(builder.get('pending_builds', [])) | 591 pending_builds_len = len(builder.get('pending_builds', [])) |
588 if pending_builds_len > max_pendings: | 592 if pending_builds_len > max_pendings: |
589 out.append('%s has %d build(s) pending' % | 593 out.append('%s has %d build(s) pending' % |
590 (builder_name, pending_builds_len)) | 594 (builder_name, pending_builds_len)) |
591 if out: | 595 if out: |
592 return [output_api.PresubmitPromptWarning( | 596 return [output_api.PresubmitPromptWarning( |
593 'Build(s) pending. It is suggested to wait that no more than %d ' | 597 'Build(s) pending. It is suggested to wait that no more than %d ' |
594 'builds are pending.' % max_pendings, | 598 'builds are pending.' % max_pendings, |
595 long_text='\n'.join(out))] | 599 long_text='\n'.join(out))] |
596 return [] | 600 return [] |
OLD | NEW |