From 866be0f290fcbe1793e5ab216bb324a4a22d48b5 Mon Sep 17 00:00:00 2001 From: Peter Wen Date: Wed, 30 Jun 2021 16:34:06 +0000 Subject: [PATCH] Add an option to specify pylint version This allows us to migrate PRESUBMIT.py files over to pylint-2.6 bit by bit. It also allows us to support and upgrade pylint to newer versions in the future. Bug: 1221143 Fixed: 1221143 Change-Id: I9af96f5f06caf48e9923ad5fae75b98a0a7aeb49 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2994723 Commit-Queue: Peter Wen Auto-Submit: Peter Wen Reviewed-by: Dirk Pranke --- presubmit_canned_checks.py | 9 +++++++-- pylint-1.5.bat | 12 ++++++++++++ tests/presubmit_unittest.py | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 pylint-1.5.bat diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index 3ffd7d4b9..40e91efdf 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -909,16 +909,21 @@ def GetPylint(input_api, files_to_skip=None, disabled_warnings=None, extra_paths_list=None, - pylintrc=None): + pylintrc=None, + version='1.5'): """Run pylint on python files. The default files_to_check enforces looking only at *.py files. + + Currently only pylint version '1.5' and '2.6' are supported. """ files_to_check = tuple(files_to_check or (r'.*\.py$', )) files_to_skip = tuple(files_to_skip or input_api.DEFAULT_FILES_TO_SKIP) extra_paths_list = extra_paths_list or [] + assert version in ('1.5', '2.6'), 'Unsupported pylint version: ' + version + if input_api.is_committing: error_type = output_api.PresubmitError else: @@ -969,7 +974,7 @@ def GetPylint(input_api, # Windows needs help running python files so we explicitly specify # the interpreter to use. It also has limitations on the size of # the command-line, so we pass arguments via a pipe. - tool = input_api.os_path.join(_HERE, 'pylint') + tool = input_api.os_path.join(_HERE, 'pylint-' + version) kwargs = {'env': env} if input_api.platform == 'win32': # On Windows, scripts on the current directory take precedence over PATH. diff --git a/pylint-1.5.bat b/pylint-1.5.bat new file mode 100644 index 000000000..4153985ed --- /dev/null +++ b/pylint-1.5.bat @@ -0,0 +1,12 @@ +@echo off +:: Copyright 2021 The Chromium Authors. All rights reserved. +:: Use of this source code is governed by a BSD-style license that can be +:: found in the LICENSE file. +setlocal + +:: Ensure that "depot_tools" is somewhere in PATH so this tool can be used +:: standalone, but allow other PATH manipulations to take priority. +set PATH=%PATH%;%~dp0 + +:: Defer control. +vpython "%~dp0\pylint-1.5" %* diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index 0ae7d80f5..402f1c295 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -2519,7 +2519,7 @@ the current line as well! subprocess.Popen.return_value = process presubmit.sigint_handler.wait.return_value = ('', None) - pylint = os.path.join(_ROOT, 'pylint') + pylint = os.path.join(_ROOT, 'pylint-1.5') pylintrc = os.path.join(_ROOT, 'pylintrc') env = {str('PYTHONPATH'): str('')} if sys.platform == 'win32':