Commit 443f9851 authored by Bruce Dawson's avatar Bruce Dawson Committed by LUCI CQ

Improve Python 2 presubmit warning

The warning that a PRESUBMIT.py file was still being run under Python 2
was apparently too polite as one was just added. This change adds
instructions on how to prevent this, which should make it clear that
the behavior is not desirable.

The warning was added in crrev.com/c/3826917.

Bug: 1313804
Change-Id: I81a6ea45907b5ea00e7d945c3131a329708cc377
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3878875
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
Reviewed-by: 's avatarAravind Vasudevan <aravindvasudev@google.com>
parent 4858aea0
......@@ -1477,7 +1477,9 @@ def DoPostUploadExecuter(change, gerrit_obj, verbose, use_python3=False):
presubmit_script = gclient_utils.FileRead(filename).replace('\r\n', '\n')
if _ShouldRunPresubmit(presubmit_script, use_python3):
if sys.version_info[0] == 2:
sys.stdout.write('Running %s under Python 2.\n' % filename)
sys.stdout.write(
'Running %s under Python 2. Add USE_PYTHON3 = True to prevent '
'this.\n' % filename)
elif verbose:
sys.stdout.write('Running %s\n' % filename)
results.extend(executer.ExecPresubmitScript(
......@@ -1751,7 +1753,9 @@ def DoPresubmitChecks(change,
presubmit_script = gclient_utils.FileRead(filename).replace('\r\n', '\n')
if _ShouldRunPresubmit(presubmit_script, use_python3):
if sys.version_info[0] == 2:
sys.stdout.write('Running %s under Python 2.\n' % filename)
sys.stdout.write(
'Running %s under Python 2. Add USE_PYTHON3 = True to prevent '
'this.\n' % filename)
elif verbose:
sys.stdout.write('Running %s\n' % filename)
results += executer.ExecPresubmitScript(presubmit_script, filename)
......
......@@ -624,8 +624,10 @@ class PresubmitUnittest(PresubmitTestsBase):
expected = (r'Running Python ' + str(sys.version_info.major) +
r' post upload checks \.\.\.\n')
if sys.version_info[0] == 2:
expected += r'Running .*PRESUBMIT.py under Python 2.\n'
expected += r'Running .*PRESUBMIT.py under Python 2.\n'
expected += ('Running .*PRESUBMIT.py under Python 2. Add USE_PYTHON3 = '
'True to prevent this.\n')
expected += ('Running .*PRESUBMIT.py under Python 2. Add USE_PYTHON3 = '
'True to prevent this.\n')
self.assertRegexpMatches(sys.stdout.getvalue(), expected)
def testDoPostUploadExecuterWarning(self):
......@@ -659,7 +661,8 @@ class PresubmitUnittest(PresubmitTestsBase):
extra = ''
if sys.version_info[0] == 2:
extra = r'Running .*PRESUBMIT.py under Python 2.\n'
extra = ('Running .*PRESUBMIT.py under Python 2. Add USE_PYTHON3 = True '
'to prevent this.\n')
expected = ('Running Python ' + str(sys.version_info.major) + ' '
'post upload checks \.\.\.\n'
'%s'
......
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