Commit bce1ec1d authored by Edward Lemur's avatar Edward Lemur Committed by LUCI CQ

Reland "presubmit_canned_checks: Run pylint on parent directory for depot_tools."

This is a reland of d3bfd23c

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 <apolito@google.com>
> Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>

No-Presubmit: True
Change-Id: I4236ec17b2642ed7f53844af532ec1f5234b80d1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1995783
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: 's avatarAnthony Polito <apolito@google.com>
parent a1266b63
......@@ -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.
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment