mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 10:41:31 +00:00
switch to 4 space indent
Leave the recipes/ code at 2 space to match the rest of the recipes
project in other repos.
Reformatted using:
files=( $(
git ls-tree -r --name-only HEAD | \
grep -Ev -e '^(third_party|recipes)/' | \
grep '\.py$';
git grep -l '#!/usr/bin/env.*python' | grep -v '\.py$'
) )
parallel ./yapf -i -- "${files[@]}"
~/chromiumos/chromite/contrib/reflow_overlong_comments "${files[@]}"
The files that still had strings that were too long were manually
reformatted because they were easy and only a few issues.
autoninja.py
clang_format.py
download_from_google_storage.py
fix_encoding.py
gclient_utils.py
git_cache.py
git_common.py
git_map_branches.py
git_reparent_branch.py
gn.py
my_activity.py
owners_finder.py
presubmit_canned_checks.py
reclient_helper.py
reclientreport.py
roll_dep.py
rustfmt.py
siso.py
split_cl.py
subcommand.py
subprocess2.py
swift_format.py
upload_to_google_storage.py
These files still had lines (strings) that were too long, so the pylint
warnings were suppressed with a TODO.
auth.py
gclient.py
gclient_eval.py
gclient_paths.py
gclient_scm.py
gerrit_util.py
git_cl.py
presubmit_canned_checks.py
presubmit_support.py
scm.py
Change-Id: Ia6535c4f2c48d46b589ec1e791dde6c6b2ea858f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4836379
Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
Auto-Submit: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
This commit is contained in:
@@ -15,23 +15,21 @@ STATUS_CRASH = 'CRASH'
|
||||
STATUS_ABORT = 'ABORT'
|
||||
STATUS_SKIP = 'SKIP'
|
||||
|
||||
|
||||
# ResultDB limits failure reasons to 1024 characters.
|
||||
_FAILURE_REASON_LENGTH_LIMIT = 1024
|
||||
|
||||
|
||||
# Message to use at the end of a truncated failure reason.
|
||||
_FAILURE_REASON_TRUNCATE_TEXT = '\n...\nFailure reason was truncated.'
|
||||
|
||||
|
||||
class ResultSink(object):
|
||||
def __init__(self, session, url, prefix):
|
||||
self._session = session
|
||||
self._url = url
|
||||
self._prefix = prefix
|
||||
def __init__(self, session, url, prefix):
|
||||
self._session = session
|
||||
self._url = url
|
||||
self._prefix = prefix
|
||||
|
||||
def report(self, function_name, status, elapsed_time, failure_reason=None):
|
||||
"""Reports the result and elapsed time of a presubmit function call.
|
||||
def report(self, function_name, status, elapsed_time, failure_reason=None):
|
||||
"""Reports the result and elapsed time of a presubmit function call.
|
||||
|
||||
Args:
|
||||
function_name (str): The name of the presubmit function
|
||||
@@ -39,24 +37,24 @@ class ResultSink(object):
|
||||
elapsed_time: the time taken to invoke the presubmit function
|
||||
failure_reason (str or None): if set, the failure reason
|
||||
"""
|
||||
tr = {
|
||||
'testId': self._prefix + function_name,
|
||||
'status': status,
|
||||
'expected': status == STATUS_PASS,
|
||||
'duration': '{:.9f}s'.format(elapsed_time)
|
||||
}
|
||||
if failure_reason:
|
||||
if len(failure_reason) > _FAILURE_REASON_LENGTH_LIMIT:
|
||||
failure_reason = failure_reason[
|
||||
:-len(_FAILURE_REASON_TRUNCATE_TEXT) - 1]
|
||||
failure_reason += _FAILURE_REASON_TRUNCATE_TEXT
|
||||
tr['failureReason'] = {'primaryErrorMessage': failure_reason}
|
||||
self._session.post(self._url, json={'testResults': [tr]})
|
||||
tr = {
|
||||
'testId': self._prefix + function_name,
|
||||
'status': status,
|
||||
'expected': status == STATUS_PASS,
|
||||
'duration': '{:.9f}s'.format(elapsed_time)
|
||||
}
|
||||
if failure_reason:
|
||||
if len(failure_reason) > _FAILURE_REASON_LENGTH_LIMIT:
|
||||
failure_reason = failure_reason[:-len(
|
||||
_FAILURE_REASON_TRUNCATE_TEXT) - 1]
|
||||
failure_reason += _FAILURE_REASON_TRUNCATE_TEXT
|
||||
tr['failureReason'] = {'primaryErrorMessage': failure_reason}
|
||||
self._session.post(self._url, json={'testResults': [tr]})
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def client(prefix):
|
||||
"""Returns a client for ResultSink.
|
||||
"""Returns a client for ResultSink.
|
||||
|
||||
This is a context manager that returns a client for ResultSink,
|
||||
if LUCI_CONTEXT with a section of result_sink is present. When the context
|
||||
@@ -71,24 +69,24 @@ def client(prefix):
|
||||
Returns:
|
||||
An instance of ResultSink() if the luci context is present. None, otherwise.
|
||||
"""
|
||||
luci_ctx = os.environ.get('LUCI_CONTEXT')
|
||||
if not luci_ctx:
|
||||
yield None
|
||||
return
|
||||
luci_ctx = os.environ.get('LUCI_CONTEXT')
|
||||
if not luci_ctx:
|
||||
yield None
|
||||
return
|
||||
|
||||
sink_ctx = None
|
||||
with open(luci_ctx) as f:
|
||||
sink_ctx = json.load(f).get('result_sink')
|
||||
if not sink_ctx:
|
||||
yield None
|
||||
return
|
||||
sink_ctx = None
|
||||
with open(luci_ctx) as f:
|
||||
sink_ctx = json.load(f).get('result_sink')
|
||||
if not sink_ctx:
|
||||
yield None
|
||||
return
|
||||
|
||||
url = 'http://{0}/prpc/luci.resultsink.v1.Sink/ReportTestResults'.format(
|
||||
sink_ctx['address'])
|
||||
with requests.Session() as s:
|
||||
s.headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'Authorization': 'ResultSink {0}'.format(sink_ctx['auth_token'])
|
||||
}
|
||||
yield ResultSink(s, url, prefix)
|
||||
url = 'http://{0}/prpc/luci.resultsink.v1.Sink/ReportTestResults'.format(
|
||||
sink_ctx['address'])
|
||||
with requests.Session() as s:
|
||||
s.headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'Authorization': 'ResultSink {0}'.format(sink_ctx['auth_token'])
|
||||
}
|
||||
yield ResultSink(s, url, prefix)
|
||||
|
||||
Reference in New Issue
Block a user