| 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 | 10 |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 | 646 |
| 647 # Copy the system path to the environment so pylint can find the right | 647 # Copy the system path to the environment so pylint can find the right |
| 648 # imports. | 648 # imports. |
| 649 env = input_api.environ.copy() | 649 env = input_api.environ.copy() |
| 650 import sys | 650 import sys |
| 651 env['PYTHONPATH'] = input_api.os_path.pathsep.join(sys.path) | 651 env['PYTHONPATH'] = input_api.os_path.pathsep.join(sys.path) |
| 652 | 652 |
| 653 def run_lint(files): | 653 def run_lint(files): |
| 654 # We can't import pylint directly due to licensing issues, so we run | 654 # We can't import pylint directly due to licensing issues, so we run |
| 655 # it in another process. Windows needs help running python files so we | 655 # it in another process. Windows needs help running python files so we |
| 656 # explicitly specify the interpreter to use. | 656 # explicitly specify the interpreter to use. It also has limitations on |
| 657 # the size of the command-line, so we pass arguments via a pipe. |
| 657 command = [input_api.python_executable, | 658 command = [input_api.python_executable, |
| 658 input_api.os_path.join(_HERE, 'third_party', 'pylint.py')] | 659 input_api.os_path.join(_HERE, 'third_party', 'pylint.py'), |
| 660 '--args-on-stdin'] |
| 659 try: | 661 try: |
| 660 return input_api.subprocess.call(command + files + extra_args, env=env) | 662 child = input_api.subprocess.Popen(command, env=env, |
| 663 stdin=input_api.subprocess.PIPE) |
| 664 |
| 665 # Dump the arguments to the child process via a pipe. |
| 666 for filename in files: |
| 667 child.stdin.write(filename + '\n') |
| 668 for arg in extra_args: |
| 669 child.stdin.write(arg + '\n') |
| 670 child.stdin.close() |
| 671 |
| 672 child.communicate() |
| 673 return child.returncode |
| 661 except OSError: | 674 except OSError: |
| 662 return 'Pylint failed!' | 675 return 'Pylint failed!' |
| 663 | 676 |
| 664 result = None | 677 result = None |
| 665 if not input_api.verbose: | 678 if not input_api.verbose: |
| 666 result = run_lint(sorted(files)) | 679 result = run_lint(sorted(files)) |
| 667 else: | 680 else: |
| 668 for filename in sorted(files): | 681 for filename in sorted(files): |
| 669 print('Running pylint on %s' % filename) | 682 print('Running pylint on %s' % filename) |
| 670 result = run_lint([filename]) or result | 683 result = run_lint([filename]) or result |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( | 945 results.extend(input_api.canned_checks.CheckSvnForCommonMimeTypes( |
| 933 input_api, output_api)) | 946 input_api, output_api)) |
| 934 snapshot("checking license") | 947 snapshot("checking license") |
| 935 results.extend(input_api.canned_checks.CheckLicense( | 948 results.extend(input_api.canned_checks.CheckLicense( |
| 936 input_api, output_api, license_header, source_file_filter=sources)) | 949 input_api, output_api, license_header, source_file_filter=sources)) |
| 937 snapshot("checking was uploaded") | 950 snapshot("checking was uploaded") |
| 938 results.extend(input_api.canned_checks.CheckChangeWasUploaded( | 951 results.extend(input_api.canned_checks.CheckChangeWasUploaded( |
| 939 input_api, output_api)) | 952 input_api, output_api)) |
| 940 snapshot("done") | 953 snapshot("done") |
| 941 return results | 954 return results |
| OLD | NEW |