From bce1ec1d578337e7957428f46319e778cf4e0b41 Mon Sep 17 00:00:00 2001 From: Edward Lemur Date: Mon, 13 Jan 2020 20:19:16 +0000 Subject: [PATCH] Reland "presubmit_canned_checks: Run pylint on parent directory for depot_tools." This is a reland of d3bfd23c6d01917df7d433216ab85236b15f2dca Don't modify cwd for paths other than depot_tools. Original change's description: > 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 No-Presubmit: True Change-Id: I4236ec17b2642ed7f53844af532ec1f5234b80d1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1995783 Commit-Queue: Edward Lesmes Reviewed-by: Anthony Polito --- presubmit_canned_checks.py | 14 +++++++++++++- tests/presubmit_unittest.py | 4 +++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index 13e77fe43..d62859b94 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -885,8 +885,18 @@ 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') + kwargs = {'env': env} 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. + cwd = input_api.change.RepositoryRoot() + if input_api.os_path.basename(cwd) == 'depot_tools': + kwargs['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: description = flist[0] @@ -901,10 +911,12 @@ def GetPylint(input_api, output_api, white_list=None, black_list=None, args.append('--jobs=%s' % input_api.cpu_count) description += ' on %d cores' % input_api.cpu_count + kwargs['stdin'] = '\n'.join(args + flist) + return input_api.Command( name='Pylint (%s)' % description, cmd=cmd, - kwargs={'env': env, 'stdin': '\n'.join(args + flist)}, + kwargs=kwargs, 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