From d3bfd23c6d01917df7d433216ab85236b15f2dca Mon Sep 17 00:00:00 2001 From: Edward Lemur Date: Fri, 10 Jan 2020 23:07:53 +0000 Subject: [PATCH] presubmit_canned_checks: Run pylint on parent directory for depot_tools. On Windows, scripts on the current directory take precedence over PATH. When pylint.bat calls vpython, it executes the vpython of the depot_tools under test instead of the one in the bot. As a workaround, run the tests from the parent directory instead. Change-Id: I7fa3f5b268df516194063ff39907ada18f7ef544 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1994216 Reviewed-by: Anthony Polito Commit-Queue: Edward Lesmes --- presubmit_canned_checks.py | 10 +++++++++- tests/presubmit_unittest.py | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index 13e77fe43..41d323725 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -885,7 +885,15 @@ def GetPylint(input_api, output_api, white_list=None, black_list=None, # 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') + cwd = input_api.change.RepositoryRoot() if input_api.platform == 'win32': + # On Windows, scripts on the current directory take precedence over PATH. + # When `pylint.bat` calls `vpython`, it will execute the `vpython` of the + # depot_tools under test instead of the one in the bot. + # As a workaround, we run the tests from the parent directory instead. + if input_api.os_path.basename(cwd) == 'depot_tools': + cwd = input_api.os_path.dirname(cwd) + flist = [input_api.os_path.join('depot_tools', f) for f in flist] tool += '.bat' cmd = [tool, '--args-on-stdin'] if len(flist) == 1: @@ -904,7 +912,7 @@ def GetPylint(input_api, output_api, white_list=None, black_list=None, return input_api.Command( name='Pylint (%s)' % description, cmd=cmd, - kwargs={'env': env, 'stdin': '\n'.join(args + flist)}, + kwargs={'env': env, 'stdin': '\n'.join(args + flist), 'cwd': cwd}, message=error_type) # Always run pylint and pass it all the py files at once. diff --git a/tests/presubmit_unittest.py b/tests/presubmit_unittest.py index 0fce5d913..90ac3af3c 100755 --- a/tests/presubmit_unittest.py +++ b/tests/presubmit_unittest.py @@ -2106,7 +2106,9 @@ the current line as well! self.assertEqual(results, []) def testCannedRunPylint(self): - input_api = self.MockInputApi(None, True) + change = mock.Mock() + change.RepositoryRoot.return_value = 'CWD' + input_api = self.MockInputApi(change, True) input_api.environ = mock.MagicMock(os.environ) input_api.environ.copy.return_value = {} input_api.AffectedSourceFiles.return_value = True