From 44a8a8d49a33aa5673f3e93f42471a3b15a2a07a Mon Sep 17 00:00:00 2001 From: Oliver Newman Date: Mon, 6 Jan 2025 08:48:00 -0800 Subject: [PATCH] [git] Remove usage of recipe_util.format_ex This function was a shim to ensure consistency between Python 2 and 3. It's no longer necessary now that recipes don't support Python 2 anymore, and is being deleted in crrev.com/c/6133284. Also update two tests to be less sensitive to the exact format of the summary markdown produced when an exception occurs, since some single quotes are now changed to double quotes. Change-Id: Ia8a7bd9be5f03302049f6798c51b8e4e8bdc9784 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6142074 Reviewed-by: Gavin Mak Auto-Submit: Oliver Newman Commit-Queue: Oliver Newman --- recipes/README.recipes.md | 28 +++++++++---------- .../recipe_modules/gclient/tests/diff_deps.py | 12 ++++---- recipes/recipe_modules/git/api.py | 3 +- .../count-objects_with_bad_output.json | 2 +- ...t-objects_with_bad_output_fails_build.json | 2 +- .../full.expected/new_branch_failed.json | 2 +- 6 files changed, 23 insertions(+), 26 deletions(-) diff --git a/recipes/README.recipes.md b/recipes/README.recipes.md index 1f1d0028a..24b5f5f80 100644 --- a/recipes/README.recipes.md +++ b/recipes/README.recipes.md @@ -432,13 +432,13 @@ Returns: [DEPS](/recipes/recipe_modules/git/__init__.py#3): [depot\_tools](#recipe_modules-depot_tools), [recipe\_engine/buildbucket][recipe_engine/recipe_modules/buildbucket], [recipe\_engine/context][recipe_engine/recipe_modules/context], [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/platform][recipe_engine/recipe_modules/platform], [recipe\_engine/properties][recipe_engine/recipe_modules/properties], [recipe\_engine/raw\_io][recipe_engine/recipe_modules/raw_io], [recipe\_engine/runtime][recipe_engine/recipe_modules/runtime], [recipe\_engine/step][recipe_engine/recipe_modules/step] -#### **class [GitApi](/recipes/recipe_modules/git/api.py#11)([RecipeApi][recipe_engine/wkt/RecipeApi]):** +#### **class [GitApi](/recipes/recipe_modules/git/api.py#10)([RecipeApi][recipe_engine/wkt/RecipeApi]):** -— **def [\_\_call\_\_](/recipes/recipe_modules/git/api.py#14)(self, \*args, \*\*kwargs):** +— **def [\_\_call\_\_](/recipes/recipe_modules/git/api.py#13)(self, \*args, \*\*kwargs):** Returns a git command step. -— **def [bundle\_create](/recipes/recipe_modules/git/api.py#391)(self, bundle_path, rev_list_args=None, \*\*kwargs):** +— **def [bundle\_create](/recipes/recipe_modules/git/api.py#390)(self, bundle_path, rev_list_args=None, \*\*kwargs):** Runs 'git bundle create' on a Git repository. @@ -448,11 +448,11 @@ Args: refs in the Git checkout will be bundled. * kwargs: Forwarded to '__call__'. -— **def [cat\_file\_at\_commit](/recipes/recipe_modules/git/api.py#34)(self, file_path, commit_hash, remote_name=None, \*\*kwargs):** +— **def [cat\_file\_at\_commit](/recipes/recipe_modules/git/api.py#33)(self, file_path, commit_hash, remote_name=None, \*\*kwargs):** Outputs the contents of a file at a given revision. -— **def [checkout](/recipes/recipe_modules/git/api.py#107)(self, url, ref=None, dir_path=None, recursive=False, submodules=True, submodule_update_force=False, keep_paths=None, step_suffix=None, curl_trace_file=None, raise_on_failure=True, set_got_revision=False, remote_name=None, display_fetch_size=None, file_name=None, submodule_update_recursive=True, use_git_cache=False, progress=True, tags=False, depth=None):** +— **def [checkout](/recipes/recipe_modules/git/api.py#106)(self, url, ref=None, dir_path=None, recursive=False, submodules=True, submodule_update_force=False, keep_paths=None, step_suffix=None, curl_trace_file=None, raise_on_failure=True, set_got_revision=False, remote_name=None, display_fetch_size=None, file_name=None, submodule_update_recursive=True, use_git_cache=False, progress=True, tags=False, depth=None):** Performs a full git checkout and returns sha1 of checked out revision. @@ -493,7 +493,7 @@ Args: Returns: If the checkout was successful, this returns the commit hash of the checked-out-repo. Otherwise this returns None. -— **def [config\_get](/recipes/recipe_modules/git/api.py#360)(self, prop_name, \*\*kwargs):** +— **def [config\_get](/recipes/recipe_modules/git/api.py#359)(self, prop_name, \*\*kwargs):** Returns git config output. @@ -503,7 +503,7 @@ Args: Returns: (str) The Git config output, or None if no output was generated. -— **def [count\_objects](/recipes/recipe_modules/git/api.py#42)(self, previous_result=None, raise_on_failure=False, \*\*kwargs):** +— **def [count\_objects](/recipes/recipe_modules/git/api.py#41)(self, previous_result=None, raise_on_failure=False, \*\*kwargs):** Returns `git count-objects` result as a dict. @@ -516,11 +516,11 @@ Args: Returns: A dict of count-object values, or None if count-object run failed. -— **def [fetch\_tags](/recipes/recipe_modules/git/api.py#28)(self, remote_name=None, \*\*kwargs):** +— **def [fetch\_tags](/recipes/recipe_modules/git/api.py#27)(self, remote_name=None, \*\*kwargs):** Fetches all tags from the remote. -— **def [get\_remote\_url](/recipes/recipe_modules/git/api.py#379)(self, remote_name=None, \*\*kwargs):** +— **def [get\_remote\_url](/recipes/recipe_modules/git/api.py#378)(self, remote_name=None, \*\*kwargs):** Returns the remote Git repository URL, or None. @@ -530,11 +530,11 @@ Args: Returns: (str) The URL of the remote Git repository, or None. -— **def [get\_timestamp](/recipes/recipe_modules/git/api.py#331)(self, commit='HEAD', test_data=None, \*\*kwargs):** +— **def [get\_timestamp](/recipes/recipe_modules/git/api.py#330)(self, commit='HEAD', test_data=None, \*\*kwargs):** Find and return the timestamp of the given commit. -— **def [ls\_remote](/recipes/recipe_modules/git/api.py#472)(self, url, ref, name=None, \*\*kwargs):** +— **def [ls\_remote](/recipes/recipe_modules/git/api.py#471)(self, url, ref, name=None, \*\*kwargs):** Request the head revision for a given ref using ls-remote. Raise a StepFailure if the ref does not exist, or more than one ref was found. @@ -546,7 +546,7 @@ Args: Returns: A git revision. -— **def [new\_branch](/recipes/recipe_modules/git/api.py#404)(self, branch, name=None, upstream=None, upstream_current=False, \*\*kwargs):** +— **def [new\_branch](/recipes/recipe_modules/git/api.py#403)(self, branch, name=None, upstream=None, upstream_current=False, \*\*kwargs):** Runs git new-branch on a Git repository, to be used before git cl upload. @@ -558,7 +558,7 @@ Args: * upstream_current (bool): whether to use '--upstream_current'. * kwargs: Forwarded to '__call__'. -— **def [number](/recipes/recipe_modules/git/api.py#435)(self, commitrefs=None, test_values=None):** +— **def [number](/recipes/recipe_modules/git/api.py#434)(self, commitrefs=None, test_values=None):** Computes the generation number of some commits. @@ -575,7 +575,7 @@ A list of strings containing the generation numbers of the commits. If non-empty commitrefs was provided, the order of the returned numbers will correspond to the order of the provided commitrefs. -— **def [rebase](/recipes/recipe_modules/git/api.py#340)(self, name_prefix, branch, dir_path, remote_name=None, \*\*kwargs):** +— **def [rebase](/recipes/recipe_modules/git/api.py#339)(self, name_prefix, branch, dir_path, remote_name=None, \*\*kwargs):** Runs rebase HEAD onto branch diff --git a/recipes/recipe_modules/gclient/tests/diff_deps.py b/recipes/recipe_modules/gclient/tests/diff_deps.py index 1c4f99d83..4ea561e7d 100644 --- a/recipes/recipe_modules/gclient/tests/diff_deps.py +++ b/recipes/recipe_modules/gclient/tests/diff_deps.py @@ -3,7 +3,7 @@ # found in the LICENSE file. from recipe_engine.post_process import (DropExpectation, StatusSuccess, - SummaryMarkdown) + SummaryMarkdownRE) PYTHON_VERSION_COMPATIBILITY = 'PY3' @@ -69,9 +69,8 @@ def GenTests(api): ), api.expect_exception('DepsDiffException'), api.post_process( - SummaryMarkdown, - "Uncaught Exception: DepsDiffException('Unexpected result: autoroll " - "diff found 0 files changed')"), + SummaryMarkdownRE, + "Unexpected result: autoroll diff found 0 files changed"), api.post_process(DropExpectation), status="INFRA_FAILURE") @@ -85,9 +84,8 @@ def GenTests(api): ), api.expect_exception('DepsDiffException'), api.post_process( - SummaryMarkdown, - "Uncaught Exception: DepsDiffException('Couldn't checkout previous " - "ref: fatal: bad object abcdef1234567890')"), + SummaryMarkdownRE, + "Couldn't checkout previous ref: fatal: bad object abcdef1234567890"), api.post_process(DropExpectation), status="INFRA_FAILURE") diff --git a/recipes/recipe_modules/git/api.py b/recipes/recipe_modules/git/api.py index 1d4ea0f3c..663e7bae2 100644 --- a/recipes/recipe_modules/git/api.py +++ b/recipes/recipe_modules/git/api.py @@ -6,7 +6,6 @@ import itertools import re from recipe_engine import recipe_api -from recipe_engine import util as recipe_util class GitApi(recipe_api.RecipeApi): _GIT_HASH_RE = re.compile('[0-9a-f]{40}', re.IGNORECASE) @@ -98,7 +97,7 @@ class GitApi(recipe_api.RecipeApi): return result except Exception as ex: if step_result: - step_result.presentation.logs['exception'] = recipe_util.format_ex(ex) + step_result.presentation.logs['exception'] = repr(ex) step_result.presentation.status = self.m.step.WARNING if raise_on_failure: raise recipe_api.InfraFailure('count-objects failed: %s' % ex) diff --git a/recipes/recipe_modules/git/examples/full.expected/count-objects_with_bad_output.json b/recipes/recipe_modules/git/examples/full.expected/count-objects_with_bad_output.json index 4a73b43e1..f0c5bc0a7 100644 --- a/recipes/recipe_modules/git/examples/full.expected/count-objects_with_bad_output.json +++ b/recipes/recipe_modules/git/examples/full.expected/count-objects_with_bad_output.json @@ -97,7 +97,7 @@ "infra_step": true, "name": "count-objects", "~followup_annotations": [ - "@@@STEP_LOG_LINE@exception@ValueError('invalid literal for int() with base 10: 'xxx'')@@@", + "@@@STEP_LOG_LINE@exception@ValueError(\"invalid literal for int() with base 10: 'xxx'\")@@@", "@@@STEP_LOG_END@exception@@@", "@@@STEP_WARNINGS@@@" ] diff --git a/recipes/recipe_modules/git/examples/full.expected/count-objects_with_bad_output_fails_build.json b/recipes/recipe_modules/git/examples/full.expected/count-objects_with_bad_output_fails_build.json index f1b351c7b..92b3dae34 100644 --- a/recipes/recipe_modules/git/examples/full.expected/count-objects_with_bad_output_fails_build.json +++ b/recipes/recipe_modules/git/examples/full.expected/count-objects_with_bad_output_fails_build.json @@ -97,7 +97,7 @@ "infra_step": true, "name": "count-objects", "~followup_annotations": [ - "@@@STEP_LOG_LINE@exception@ValueError('invalid literal for int() with base 10: 'xxx'')@@@", + "@@@STEP_LOG_LINE@exception@ValueError(\"invalid literal for int() with base 10: 'xxx'\")@@@", "@@@STEP_LOG_END@exception@@@", "@@@STEP_WARNINGS@@@" ] diff --git a/recipes/recipe_modules/git/examples/full.expected/new_branch_failed.json b/recipes/recipe_modules/git/examples/full.expected/new_branch_failed.json index a0e6363f0..76678a610 100644 --- a/recipes/recipe_modules/git/examples/full.expected/new_branch_failed.json +++ b/recipes/recipe_modules/git/examples/full.expected/new_branch_failed.json @@ -197,7 +197,7 @@ " File \"RECIPE_REPO[depot_tools]/recipes/recipe_modules/git/examples/full.py\", line 82, in RunSteps", " api.git.new_branch('failed_new_branch', upstream='will_fail', upstream_current=True) #pylint: disable = line-too-long", " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^", - " File \"RECIPE_REPO[depot_tools]/recipes/recipe_modules/git/api.py\", line 421, in new_branch", + " File \"RECIPE_REPO[depot_tools]/recipes/recipe_modules/git/api.py\", line 420, in new_branch", " raise ValueError('Can not define both upstream and upstream_current')", "ValueError: Can not define both upstream and upstream_current" ]