Commit d6d5c46c authored by Gavin Mak's avatar Gavin Mak Committed by LUCI CQ

Add PYTHON_VERSION_COMPATIBILITY to gitiles and bot_update

Setting PYTHON_VERSION_COMPATIBILITY = PY2+3 makes "recipe.py test" run
tests in both py2 and py3.

Bug: 1227140
Change-Id: I56a47f0491cbade172e1dc1239cbf6c2a0faa64f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3116850
Commit-Queue: Gavin Mak <gavinmak@google.com>
Reviewed-by: 's avatarJosip Sokcevic <sokcevic@google.com>
parent 5d0fbd6a
This diff is collapsed.
PYTHON_VERSION_COMPATIBILITY = 'PY2+3'
DEPS = [
'depot_tools',
'gclient',
......
......@@ -2,6 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
PYTHON_VERSION_COMPATIBILITY = 'PY2+3'
DEPS = [
'bot_update',
'gclient',
......
......@@ -100,11 +100,11 @@ class BotUpdateTestApi(recipe_test_api.RecipeTestApi):
@staticmethod
def gen_revision(project):
"""Hash project to bogus deterministic git hash values."""
h = hashlib.sha1(project)
h = hashlib.sha1(project.encode('utf-8'))
return h.hexdigest()
@staticmethod
def gen_commit_position(project):
"""Hash project to bogus deterministic Cr-Commit-Position values."""
h = hashlib.sha1(project)
h = hashlib.sha1(project.encode('utf-8'))
return struct.unpack('!I', h.digest()[:4])[0] % 300000
......@@ -2,6 +2,10 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from recipe_engine import post_process
PYTHON_VERSION_COMPATIBILITY = 'PY2+3'
DEPS = [
'bot_update',
'gclient',
......@@ -11,8 +15,6 @@ DEPS = [
'recipe_engine/step',
]
from recipe_engine import post_process
def RunSteps(api):
src_cfg = api.gclient.make_config()
......
......@@ -4,6 +4,8 @@
from recipe_engine import post_process
PYTHON_VERSION_COMPATIBILITY = 'PY2+3'
DEPS = [
'bot_update',
'gclient',
......
......@@ -2,6 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
PYTHON_VERSION_COMPATIBILITY = 'PY2+3'
DEPS = [
'recipe_engine/json',
'recipe_engine/path',
......
......@@ -5,6 +5,7 @@
from __future__ import division
import base64
import sys
try:
import urlparse
......@@ -157,7 +158,11 @@ class Gitiles(recipe_api.RecipeApi):
**kwargs)
if step_result.json.output['value'] is None:
return None
return base64.b64decode(step_result.json.output['value'])
# TODO(crbug.com/1227140): Clean up when py2 is no longer supported.
value = base64.b64decode(step_result.json.output['value'])
if sys.version_info >= (3,):
return value.decode('utf-8')
return value
def download_archive(self, repository_url, destination,
revision='refs/heads/main'):
......
......@@ -2,6 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
PYTHON_VERSION_COMPATIBILITY = 'PY2+3'
DEPS = [
'gitiles',
'recipe_engine/json',
......
......@@ -87,9 +87,15 @@ class GitilesTestApi(recipe_test_api.RecipeTestApi):
return d
def make_hash(self, *bases):
return hashlib.sha1(':'.join(bases)).hexdigest()
return hashlib.sha1(':'.join(bases).encode('utf-8')).hexdigest()
def make_encoded_file(self, data):
value = None
# TODO(crbug.com/1227140): Clean up when py2 is no longer supported.
try:
value = base64.b64encode(data.encode('utf-8')).decode('utf-8')
except UnicodeDecodeError: #pragma: nocover
value = base64.b64encode(data)
return self.m.json.output({
'value': base64.b64encode(data),
'value': value,
})
......@@ -2,6 +2,8 @@
# Use of this source code is governed under the Apache License, Version 2.0
# that can be found in the LICENSE file.
PYTHON_VERSION_COMPATIBILITY = 'PY2+3'
DEPS = [
'gitiles',
'recipe_engine/properties',
......
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