Commit d3bfd23c authored by Edward Lemur's avatar Edward Lemur Committed by Commit Bot

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/+/1994216Reviewed-by: 's avatarAnthony Polito <apolito@google.com>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
parent b800fde5
......@@ -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.
......
......@@ -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