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

This is a reland of d3bfd23c6d

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: Anthony Polito <apolito@google.com>
changes/83/1995783/8
Edward Lemur 5 years ago committed by LUCI CQ
parent a1266b63b5
commit bce1ec1d57

@ -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 interpreter to use. It also has limitations on the size of
# the command-line, so we pass arguments via a pipe. # 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')
kwargs = {'env': env}
if input_api.platform == 'win32': 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' tool += '.bat'
cmd = [tool, '--args-on-stdin'] cmd = [tool, '--args-on-stdin']
if len(flist) == 1: if len(flist) == 1:
description = flist[0] 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) args.append('--jobs=%s' % input_api.cpu_count)
description += ' on %d cores' % input_api.cpu_count description += ' on %d cores' % input_api.cpu_count
kwargs['stdin'] = '\n'.join(args + flist)
return input_api.Command( return input_api.Command(
name='Pylint (%s)' % description, name='Pylint (%s)' % description,
cmd=cmd, cmd=cmd,
kwargs={'env': env, 'stdin': '\n'.join(args + flist)}, kwargs=kwargs,
message=error_type) message=error_type)
# Always run pylint and pass it all the py files at once. # Always run pylint and pass it all the py files at once.

@ -2106,7 +2106,9 @@ the current line as well!
self.assertEqual(results, []) self.assertEqual(results, [])
def testCannedRunPylint(self): 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 = mock.MagicMock(os.environ)
input_api.environ.copy.return_value = {} input_api.environ.copy.return_value = {}
input_api.AffectedSourceFiles.return_value = True input_api.AffectedSourceFiles.return_value = True

Loading…
Cancel
Save