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

Side by Side Diff: presubmit_canned_checks.py

Issue 5682011: Add RunPylint as a canned presubmit check. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Addressed review comments Created 10 years 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 | « PRESUBMIT.py ('k') | tests/presubmit_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 # warning messages.
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 try:
465 from pylint import lint
466 if lint.Run(sorted(files)):
467 return [output_api.PresubmitPromptWarning('Fix pylint errors first.')]
468 return []
469 except ImportError:
470 if input_api.platform == 'win32':
471 return [output_api.PresubmitNotifyResult(
472 'Warning: Can\'t run pylint because it is not installed. Please '
473 'install manually\n'
474 'Cannot do static analysis of python files.')]
475 return [output_api.PresubmitError(
476 'Please install pylint with "sudo apt-get install python-setuptools; '
477 'sudo easy_install pylint"\n'
478 'Cannot do static analysis of python files.')]
479 finally:
480 warnings.filterwarnings('default', category=DeprecationWarning)
481
482
453 def CheckRietveldTryJobExecution(input_api, output_api, host_url, platforms, 483 def CheckRietveldTryJobExecution(input_api, output_api, host_url, platforms,
454 owner): 484 owner):
455 if not input_api.is_committing: 485 if not input_api.is_committing:
456 return [] 486 return []
457 if not input_api.change.issue or not input_api.change.patchset: 487 if not input_api.change.issue or not input_api.change.patchset:
458 return [] 488 return []
459 url = '%s/%d/get_build_results/%d' % ( 489 url = '%s/%d/get_build_results/%d' % (
460 host_url, input_api.change.issue, input_api.change.patchset) 490 host_url, input_api.change.issue, input_api.change.patchset)
461 try: 491 try:
462 connection = input_api.urllib2.urlopen(url) 492 connection = input_api.urllib2.urlopen(url)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 pending_builds_len = len(builder.get('pending_builds', [])) 556 pending_builds_len = len(builder.get('pending_builds', []))
527 if pending_builds_len > max_pendings: 557 if pending_builds_len > max_pendings:
528 out.append('%s has %d build(s) pending' % 558 out.append('%s has %d build(s) pending' %
529 (builder_name, pending_builds_len)) 559 (builder_name, pending_builds_len))
530 if out: 560 if out:
531 return [output_api.PresubmitPromptWarning( 561 return [output_api.PresubmitPromptWarning(
532 'Build(s) pending. It is suggested to wait that no more than %d ' 562 'Build(s) pending. It is suggested to wait that no more than %d '
533 'builds are pending.' % max_pendings, 563 'builds are pending.' % max_pendings,
534 long_text='\n'.join(out))] 564 long_text='\n'.join(out))]
535 return [] 565 return []
OLDNEW
« no previous file with comments | « PRESUBMIT.py ('k') | tests/presubmit_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698