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

Side by Side Diff: presubmit_canned_checks.py

Issue 11776016: Fix RunPylint affected files regex issue (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Addressed M-A comments Created 7 years, 11 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 | 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) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 import os as _os 7 import os as _os
8 _HERE = _os.path.dirname(_os.path.abspath(__file__)) 8 _HERE = _os.path.dirname(_os.path.abspath(__file__))
9 9
10 10
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 if Find(filepath, black_list): 619 if Find(filepath, black_list):
620 dirnames.remove(item) 620 dirnames.remove(item)
621 for item in filenames: 621 for item in filenames:
622 filepath = input_api.os_path.join(dirpath, item)[path_len + 1:] 622 filepath = input_api.os_path.join(dirpath, item)[path_len + 1:]
623 if Find(filepath, white_list) and not Find(filepath, black_list): 623 if Find(filepath, white_list) and not Find(filepath, black_list):
624 files.append(filepath) 624 files.append(filepath)
625 return files 625 return files
626 626
627 627
628 def RunPylint(input_api, output_api, white_list=None, black_list=None, 628 def RunPylint(input_api, output_api, white_list=None, black_list=None,
629 disabled_warnings=None): 629 disabled_warnings=None, extra_paths_list=None):
630 """Run pylint on python files. 630 """Run pylint on python files.
631 631
632 The default white_list enforces looking only at *.py files. 632 The default white_list enforces looking only at *.py files.
633 """ 633 """
634 white_list = tuple(white_list or ('.*\.py$',)) 634 white_list = tuple(white_list or ('.*\.py$',))
635 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST) 635 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST)
636 extra_paths_list = extra_paths_list or []
637
636 if input_api.is_committing: 638 if input_api.is_committing:
637 error_type = output_api.PresubmitError 639 error_type = output_api.PresubmitError
638 else: 640 else:
639 error_type = output_api.PresubmitPromptWarning 641 error_type = output_api.PresubmitPromptWarning
640 642
641 # Only trigger if there is at least one python file affected. 643 # Only trigger if there is at least one python file affected.
642 src_filter = lambda x: input_api.FilterSourceFile(x, white_list, black_list) 644 rel_path = lambda x : input_api.os_path.join(input_api.os_path.relpath(
645 input_api.PresubmitLocalPath(), input_api.change.RepositoryRoot()), x)
646 src_filter = lambda x: input_api.FilterSourceFile(
647 x, map(rel_path, white_list), map(rel_path, black_list))
643 if not input_api.AffectedSourceFiles(src_filter): 648 if not input_api.AffectedSourceFiles(src_filter):
649 input_api.logging.info('Skipping pylint: no matching changes.')
644 return [] 650 return []
645 651
646 extra_args = ['--rcfile=%s' % input_api.os_path.join(_HERE, 'pylintrc')] 652 extra_args = ['--rcfile=%s' % input_api.os_path.join(_HERE, 'pylintrc')]
647 if disabled_warnings: 653 if disabled_warnings:
648 extra_args.extend(['-d', ','.join(disabled_warnings)]) 654 extra_args.extend(['-d', ','.join(disabled_warnings)])
649 655
650 files = _FetchAllFiles(input_api, white_list, black_list) 656 files = _FetchAllFiles(input_api, white_list, black_list)
651 if not files: 657 if not files:
652 return [] 658 return []
653 659
660 input_api.logging.info('Running pylint on: %s', files)
654 # Copy the system path to the environment so pylint can find the right 661 # Copy the system path to the environment so pylint can find the right
655 # imports. 662 # imports.
656 env = input_api.environ.copy() 663 env = input_api.environ.copy()
657 import sys 664 import sys
658 env['PYTHONPATH'] = input_api.os_path.pathsep.join(sys.path) 665 env['PYTHONPATH'] = input_api.os_path.pathsep.join(
666 extra_paths_list + sys.path)
659 667
660 def run_lint(files): 668 def run_lint(files):
661 # We can't import pylint directly due to licensing issues, so we run 669 # We can't import pylint directly due to licensing issues, so we run
662 # it in another process. Windows needs help running python files so we 670 # it in another process. Windows needs help running python files so we
663 # explicitly specify the interpreter to use. It also has limitations on 671 # explicitly specify the interpreter to use. It also has limitations on
664 # the size of the command-line, so we pass arguments via a pipe. 672 # the size of the command-line, so we pass arguments via a pipe.
665 command = [input_api.python_executable, 673 command = [input_api.python_executable,
666 input_api.os_path.join(_HERE, 'third_party', 'pylint.py'), 674 input_api.os_path.join(_HERE, 'third_party', 'pylint.py'),
667 '--args-on-stdin'] 675 '--args-on-stdin']
668 try: 676 try:
(...skipping 11 matching lines...) Expand all
680 return child.returncode 688 return child.returncode
681 except OSError: 689 except OSError:
682 return 'Pylint failed!' 690 return 'Pylint failed!'
683 691
684 result = None 692 result = None
685 # Always run pylint and pass it all the py files at once. 693 # Always run pylint and pass it all the py files at once.
686 # Passing py files one at time is slower and can produce 694 # Passing py files one at time is slower and can produce
687 # different results. input_api.verbose used to be used 695 # different results. input_api.verbose used to be used
688 # to enable this behaviour but differing behaviour in 696 # to enable this behaviour but differing behaviour in
689 # verbose mode is not desirable. 697 # verbose mode is not desirable.
698 # Leave this unreachable code in here so users can make
699 # a quick local edit to diagnose pylint issues more
700 # easily.
690 if True: 701 if True:
702 print('Running pylint on %d files.' % len(files))
691 result = run_lint(sorted(files)) 703 result = run_lint(sorted(files))
692 else: 704 else:
693 for filename in sorted(files): 705 for filename in sorted(files):
694 print('Running pylint on %s' % filename) 706 print('Running pylint on %s' % filename)
695 result = run_lint([filename]) or result 707 result = run_lint([filename]) or result
696 if isinstance(result, basestring): 708 if isinstance(result, basestring):
697 return [error_type(result)] 709 return [error_type(result)]
698 elif result: 710 elif result:
699 return [error_type('Fix pylint errors first.')] 711 return [error_type('Fix pylint errors first.')]
700 return [] 712 return []
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 snapshot("checking description") 993 snapshot("checking description")
982 results.extend(input_api.canned_checks.CheckChangeHasDescription( 994 results.extend(input_api.canned_checks.CheckChangeHasDescription(
983 input_api, output_api)) 995 input_api, output_api))
984 results.extend(input_api.canned_checks.CheckDoNotSubmitInDescription( 996 results.extend(input_api.canned_checks.CheckDoNotSubmitInDescription(
985 input_api, output_api)) 997 input_api, output_api))
986 snapshot("checking do not submit in files") 998 snapshot("checking do not submit in files")
987 results.extend(input_api.canned_checks.CheckDoNotSubmitInFiles( 999 results.extend(input_api.canned_checks.CheckDoNotSubmitInFiles(
988 input_api, output_api)) 1000 input_api, output_api))
989 snapshot("done") 1001 snapshot("done")
990 return results 1002 return results
OLDNEW
« no previous file with comments | « no previous file | tests/presubmit_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698