Add use_python3 to codereview.settings to set default for PRESUBMITs.
This CL adds a new field to the codereview.settings file used by
git_cl for project-wide defaults. If `USE_PYTHON3` is set to True,
then we will run the PRESUBMIT checks under Python3 by default
instead of Python2, unless the PRESUBMIT.py file contains
`USE_PYTHON3 = False` on a line by itself
(as opposed to now, where we'll use Python2 by default unless the
file contains `USE_PYTHON3 = True`).
This will allow us have Python3 be the default for new files
and to eventually eliminate any uses of `USE_PYTHON3` from the
individual presubmit files. Of course, you will have to go in and
explicitly add `USE_PYTHON3 = False` to any Py2-only files prior
to enabling this.
Bug: 1207012
Change-Id: Id8ec45b43940e5bcffeee196398c711c541e733e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2917747
Reviewed-by: Nico Weber <thakis@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@google.com>
Reviewed-by: Edward Lesmes <ehmaldonado@chromium.org>
Commit-Queue: Dirk Pranke <dpranke@google.com>
diff --git a/git_cl.py b/git_cl.py
index 4a054be..1aaf6bf 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -773,6 +773,9 @@
def GetDefaultCCList(self):
return self._GetConfig('rietveld.cc')
+ def GetUsePython3(self):
+ return self._GetConfig('rietveld.use-python3')
+
def GetSquashGerritUploads(self):
"""Returns True if uploads to Gerrit should be squashed by default."""
if self.squash_gerrit_uploads is None:
@@ -1179,6 +1182,9 @@
server = _KNOWN_GERRIT_TO_SHORT_URLS.get(server, server)
return '%s/%s' % (server, issue)
+ def GetUsePython3(self):
+ return settings.GetUsePython3()
+
def FetchDescription(self, pretty=False):
assert self.GetIssue(), 'issue is required to query Gerrit'
@@ -1343,7 +1349,8 @@
gclient_utils.FileWrite(description_file, description)
args.extend(['--json_output', json_output])
args.extend(['--description_file', description_file])
-
+ if self.GetUsePython3():
+ args.append('--use-python3')
start = time_time()
cmd = [vpython, PRESUBMIT_SUPPORT] + args
if resultdb and realm:
@@ -2953,6 +2960,7 @@
unset_error_ok=True)
SetProperty(
'format-full-by-default', 'FORMAT_FULL_BY_DEFAULT', unset_error_ok=True)
+ SetProperty('use-python3', 'USE_PYTHON3', unset_error_ok=True)
if 'GERRIT_HOST' in keyvals:
RunGit(['config', 'gerrit.host', keyvals['GERRIT_HOST']])