OLD | NEW |
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 # Justifications for each filter: | 10 # Justifications for each filter: |
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 | 764 |
765 input_api.logging.info('Running pylint on %d files', len(files)) | 765 input_api.logging.info('Running pylint on %d files', len(files)) |
766 input_api.logging.debug('Running pylint on: %s', files) | 766 input_api.logging.debug('Running pylint on: %s', files) |
767 # Copy the system path to the environment so pylint can find the right | 767 # Copy the system path to the environment so pylint can find the right |
768 # imports. | 768 # imports. |
769 env = input_api.environ.copy() | 769 env = input_api.environ.copy() |
770 import sys | 770 import sys |
771 env['PYTHONPATH'] = input_api.os_path.pathsep.join( | 771 env['PYTHONPATH'] = input_api.os_path.pathsep.join( |
772 extra_paths_list + sys.path).encode('utf8') | 772 extra_paths_list + sys.path).encode('utf8') |
773 | 773 |
774 def GetPylintCmd(files, extra, parallel): | 774 def GetPylintCmd(flist, extra, parallel): |
775 # Windows needs help running python files so we explicitly specify | 775 # Windows needs help running python files so we explicitly specify |
776 # the interpreter to use. It also has limitations on the size of | 776 # the interpreter to use. It also has limitations on the size of |
777 # the command-line, so we pass arguments via a pipe. | 777 # the command-line, so we pass arguments via a pipe. |
778 cmd = [input_api.python_executable, | 778 cmd = [input_api.python_executable, |
779 input_api.os_path.join(_HERE, 'third_party', 'pylint.py'), | 779 input_api.os_path.join(_HERE, 'third_party', 'pylint.py'), |
780 '--args-on-stdin'] | 780 '--args-on-stdin'] |
781 if len(files) == 1: | 781 if len(flist) == 1: |
782 description = files[0] | 782 description = flist[0] |
783 else: | 783 else: |
784 description = '%s files' % len(files) | 784 description = '%s files' % len(flist) |
785 | 785 |
| 786 args = extra_args[:] |
786 if extra: | 787 if extra: |
787 cmd.extend(extra) | 788 args.extend(extra) |
788 description += ' using %s' % (extra,) | 789 description += ' using %s' % (extra,) |
789 if parallel: | 790 if parallel: |
790 cmd.append('--jobs=%s' % input_api.cpu_count) | 791 args.append('--jobs=%s' % input_api.cpu_count) |
791 description += ' on %d cores' % input_api.cpu_count | 792 description += ' on %d cores' % input_api.cpu_count |
792 | 793 |
793 return input_api.Command( | 794 return input_api.Command( |
794 name='Pylint (%s)' % description, | 795 name='Pylint (%s)' % description, |
795 cmd=cmd, | 796 cmd=cmd, |
796 kwargs={'env': env, 'stdin': '\n'.join(files + extra_args)}, | 797 kwargs={'env': env, 'stdin': '\n'.join(args + flist)}, |
797 message=error_type) | 798 message=error_type) |
798 | 799 |
799 # Always run pylint and pass it all the py files at once. | 800 # Always run pylint and pass it all the py files at once. |
800 # Passing py files one at time is slower and can produce | 801 # Passing py files one at time is slower and can produce |
801 # different results. input_api.verbose used to be used | 802 # different results. input_api.verbose used to be used |
802 # to enable this behaviour but differing behaviour in | 803 # to enable this behaviour but differing behaviour in |
803 # verbose mode is not desirable. | 804 # verbose mode is not desirable. |
804 # Leave this unreachable code in here so users can make | 805 # Leave this unreachable code in here so users can make |
805 # a quick local edit to diagnose pylint issues more | 806 # a quick local edit to diagnose pylint issues more |
806 # easily. | 807 # easily. |
807 if True: | 808 if True: |
808 # pylint's cycle detection doesn't work in parallel, so spawn a second, | 809 # pylint's cycle detection doesn't work in parallel, so spawn a second, |
809 # single-threaded job for just that check. | 810 # single-threaded job for just that check. |
810 return [ | 811 |
811 GetPylintCmd(files, ["--disable=cyclic-import"], True), | 812 # Some PRESUBMITs explicitly mention cycle detection. |
812 GetPylintCmd(files, ["--disable=all", "--enable=cyclic-import"], False) | 813 if not any('R0401' in a or 'cyclic-import' in a for a in extra_args): |
813 ] | 814 return [ |
| 815 GetPylintCmd(files, ["--disable=cyclic-import"], True), |
| 816 GetPylintCmd(files, ["--disable=all", "--enable=cyclic-import"], False) |
| 817 ] |
| 818 else: |
| 819 return [ GetPylintCmd(files, [], True) ] |
| 820 |
814 else: | 821 else: |
815 return map(lambda x: GetPylintCmd([x], extra_args, 1), files) | 822 return map(lambda x: GetPylintCmd([x], [], 1), files) |
816 | 823 |
817 | 824 |
818 def RunPylint(input_api, *args, **kwargs): | 825 def RunPylint(input_api, *args, **kwargs): |
819 """Legacy presubmit function. | 826 """Legacy presubmit function. |
820 | 827 |
821 For better performance, get all tests and then pass to | 828 For better performance, get all tests and then pass to |
822 input_api.RunTests. | 829 input_api.RunTests. |
823 """ | 830 """ |
824 return input_api.RunTests(GetPylint(input_api, *args, **kwargs), False) | 831 return input_api.RunTests(GetPylint(input_api, *args, **kwargs), False) |
825 | 832 |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1142 for f in affected_files: | 1149 for f in affected_files: |
1143 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] | 1150 cmd = ['gn', 'format', '--dry-run', f.AbsoluteLocalPath()] |
1144 rc = gn.main(cmd) | 1151 rc = gn.main(cmd) |
1145 if rc == 2: | 1152 if rc == 2: |
1146 warnings.append(output_api.PresubmitPromptWarning( | 1153 warnings.append(output_api.PresubmitPromptWarning( |
1147 '%s requires formatting. Please run `gn format --in-place %s`.' % ( | 1154 '%s requires formatting. Please run `gn format --in-place %s`.' % ( |
1148 f.AbsoluteLocalPath(), f.LocalPath()))) | 1155 f.AbsoluteLocalPath(), f.LocalPath()))) |
1149 # It's just a warning, so ignore other types of failures assuming they'll be | 1156 # It's just a warning, so ignore other types of failures assuming they'll be |
1150 # caught elsewhere. | 1157 # caught elsewhere. |
1151 return warnings | 1158 return warnings |
OLD | NEW |