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

Side by Side Diff: presubmit_canned_checks.py

Issue 8363030: Improve pylint error message with an old version is used. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Better Created 9 years, 2 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 | pylintrc » ('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) 2011 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2011 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 7
8 ### Description checks 8 ### Description checks
9 9
10 def CheckChangeHasTestField(input_api, output_api): 10 def CheckChangeHasTestField(input_api, output_api):
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 import warnings 627 import warnings
628 warnings.filterwarnings('ignore', category=DeprecationWarning) 628 warnings.filterwarnings('ignore', category=DeprecationWarning)
629 try: 629 try:
630 files = _FetchAllFiles(input_api, white_list, black_list) 630 files = _FetchAllFiles(input_api, white_list, black_list)
631 if not files: 631 if not files:
632 return [] 632 return []
633 # Now that at least one python file was modified and all the python files 633 # Now that at least one python file was modified and all the python files
634 # were listed, try to run pylint. 634 # were listed, try to run pylint.
635 try: 635 try:
636 from pylint import lint 636 from pylint import lint
637 from pylint.utils import UnknownMessage
637 input_api.logging.debug( 638 input_api.logging.debug(
638 'Using pylint v%s from %s' % (lint.version, lint.__file__)) 639 'Using pylint v%s from %s' % (lint.version, lint.__file__))
639 except ImportError: 640 except ImportError:
640 if input_api.platform == 'win32': 641 if input_api.platform == 'win32':
641 return [output_api.PresubmitNotifyResult( 642 return [output_api.PresubmitNotifyResult(
642 'Warning: Can\'t run pylint because it is not installed. Please ' 643 'Warning: Can\'t run pylint because it is not installed. Please '
643 'install manually\n' 644 'install manually\n'
644 'Cannot do static analysis of python files.')] 645 'Cannot do static analysis of python files.')]
645 return [output_api.PresubmitError( 646 return [output_api.PresubmitError(
646 'Please install pylint with "sudo apt-get install python-setuptools; ' 647 'Please install pylint with "sudo apt-get install python-setuptools; '
647 'sudo easy_install pylint"\n' 648 'sudo easy_install pylint"\n'
648 'or visit http://pypi.python.org/pypi/setuptools.\n' 649 'or visit http://pypi.python.org/pypi/setuptools.\n'
649 'Cannot do static analysis of python files.')] 650 'Cannot do static analysis of python files.')]
650 651
651 def run_lint(files): 652 def run_lint(files):
652 try: 653 try:
653 lint.Run(files) 654 lint.Run(files)
654 assert False 655 assert False
655 except SystemExit, e: 656 except SystemExit, e:
656 # pylint has the bad habit of calling sys.exit(), trap it here. 657 # pylint has the bad habit of calling sys.exit(), trap it here.
657 return e.code 658 return e.code
659 except UnknownMessage, e:
660 return 'Please upgrade pylint: %s' % e
658 661
659 result = None 662 result = None
660 if not input_api.verbose: 663 if not input_api.verbose:
661 result = run_lint(sorted(files)) 664 result = run_lint(sorted(files))
662 else: 665 else:
663 for filename in sorted(files): 666 for filename in sorted(files):
664 print('Running pylint on %s' % filename) 667 print('Running pylint on %s' % filename)
665 out = run_lint([filename]) 668 result = run_lint([filename]) or result
666 if out: 669 if isinstance(result, basestring):
667 result = out 670 return [error_type(result)]
668 if result: 671 elif result:
669 return [error_type('Fix pylint errors first.')] 672 return [error_type('Fix pylint errors first.')]
670 return [] 673 return []
671 finally: 674 finally:
672 warnings.filterwarnings('default', category=DeprecationWarning) 675 warnings.filterwarnings('default', category=DeprecationWarning)
673 676
674 677
675 # TODO(dpranke): Get the host_url from the input_api instead 678 # TODO(dpranke): Get the host_url from the input_api instead
676 def CheckRietveldTryJobExecution(input_api, output_api, host_url, platforms, 679 def CheckRietveldTryJobExecution(input_api, output_api, host_url, platforms,
677 owner): 680 owner):
678 if not input_api.is_committing: 681 if not input_api.is_committing:
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( 955 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes(
953 input_api, output_api)) 956 input_api, output_api))
954 snapshot("checking license") 957 snapshot("checking license")
955 results.extend(input_api.canned_checks.CheckLicense( 958 results.extend(input_api.canned_checks.CheckLicense(
956 input_api, output_api, license_header, source_file_filter=sources)) 959 input_api, output_api, license_header, source_file_filter=sources))
957 snapshot("checking was uploaded") 960 snapshot("checking was uploaded")
958 results.extend(input_api.canned_checks.CheckChangeWasUploaded( 961 results.extend(input_api.canned_checks.CheckChangeWasUploaded(
959 input_api, output_api)) 962 input_api, output_api))
960 snapshot("done") 963 snapshot("done")
961 return results 964 return results
OLDNEW
« no previous file with comments | « no previous file | pylintrc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698