[recipe_modules/git_cl] Add migration path away from using config.py.

The usage of config in the git_cl module is wholly unnecessary - This
CL gives a trivial way to change downstream repos to use a normal method
in place of configs, which will ultimately let us remove config.py from
this module.

Change-Id: Ia02ad110c41fadcd3bada0258ba96cbe70d0e43c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4662591
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
changes/91/4662591/6
Robert Iannucci 2 years ago committed by LUCI CQ
parent 3db3276489
commit d0b85e47dc

@ -528,19 +528,26 @@ Args:
[DEPS](/recipes/recipe_modules/git_cl/__init__.py#3): [recipe\_engine/context][recipe_engine/recipe_modules/context], [recipe\_engine/raw\_io][recipe_engine/recipe_modules/raw_io], [recipe\_engine/step][recipe_engine/recipe_modules/step]
#### **class [GitClApi](/recipes/recipe_modules/git_cl/api.py#9)([RecipeApi][recipe_engine/wkt/RecipeApi]):**
#### **class [GitClApi](/recipes/recipe_modules/git_cl/api.py#11)([RecipeApi][recipe_engine/wkt/RecipeApi]):**
&mdash; **def [get\_description](/recipes/recipe_modules/git_cl/api.py#23)(self, patch_url=None, \*\*kwargs):**
&mdash; **def [get\_description](/recipes/recipe_modules/git_cl/api.py#39)(self, patch_url=None, \*\*kwargs):**
*** note
**DEPRECATED**. Consider using gerrit.get_change_description instead.
***
&mdash; **def [issue](/recipes/recipe_modules/git_cl/api.py#48)(self, \*\*kwargs):**
&mdash; **def [issue](/recipes/recipe_modules/git_cl/api.py#64)(self, \*\*kwargs):**
&mdash; **def [set\_description](/recipes/recipe_modules/git_cl/api.py#31)(self, description, patch_url=None, \*\*kwargs):**
&mdash; **def [set\_default\_repo\_location](/recipes/recipe_modules/git_cl/api.py#31)(self, path: Optional[Path]):**
&mdash; **def [upload](/recipes/recipe_modules/git_cl/api.py#41)(self, message, upload_args=None, \*\*kwargs):**
Sets the working directory where `git cl` will run, unless `cwd` from the
context module has been set.
If you set `path` to None, this will remove the default.
&mdash; **def [set\_description](/recipes/recipe_modules/git_cl/api.py#47)(self, description, patch_url=None, \*\*kwargs):**
&mdash; **def [upload](/recipes/recipe_modules/git_cl/api.py#57)(self, message, upload_args=None, \*\*kwargs):**
### *recipe_modules* / [gitiles](/recipes/recipe_modules/gitiles)
[DEPS](/recipes/recipe_modules/gitiles/__init__.py#7): [recipe\_engine/json][recipe_engine/recipe_modules/json], [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/raw\_io][recipe_engine/recipe_modules/raw_io], [recipe\_engine/step][recipe_engine/recipe_modules/step], [recipe\_engine/url][recipe_engine/recipe_modules/url]
@ -1073,10 +1080,10 @@ Raises:
&mdash; **def [RunSteps](/recipes/recipe_modules/git/tests/number.py#16)(api):**
### *recipes* / [git\_cl:examples/full](/recipes/recipe_modules/git_cl/examples/full.py)
[DEPS](/recipes/recipe_modules/git_cl/examples/full.py#11): [git\_cl](#recipe_modules-git_cl), [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/raw\_io][recipe_engine/recipe_modules/raw_io], [recipe\_engine/step][recipe_engine/recipe_modules/step]
[DEPS](/recipes/recipe_modules/git_cl/examples/full.py#6): [git\_cl](#recipe_modules-git_cl), [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/raw\_io][recipe_engine/recipe_modules/raw_io], [recipe\_engine/step][recipe_engine/recipe_modules/step]
&mdash; **def [RunSteps](/recipes/recipe_modules/git_cl/examples/full.py#19)(api):**
&mdash; **def [RunSteps](/recipes/recipe_modules/git_cl/examples/full.py#14)(api):**
### *recipes* / [gitiles:examples/full](/recipes/recipe_modules/gitiles/examples/full.py)
[DEPS](/recipes/recipe_modules/gitiles/examples/full.py#7): [gitiles](#recipe_modules-gitiles), [recipe\_engine/json][recipe_engine/recipe_modules/json], [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/properties][recipe_engine/recipe_modules/properties], [recipe\_engine/step][recipe_engine/recipe_modules/step]

@ -3,10 +3,15 @@
# found in the LICENSE file.
from recipe_engine import recipe_api
from recipe_engine.config_types import Path
from typing import Optional
import string
class GitClApi(recipe_api.RecipeApi):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._default_repo_location: Optional[Path] = None
def __call__(self, subcmd, args, name=None, **kwargs):
if not name:
@ -15,11 +20,22 @@ class GitClApi(recipe_api.RecipeApi):
if kwargs.get('suffix'):
name = name + ' (%s)' % kwargs.pop('suffix')
my_loc = self.c.repo_location if self.c else None
my_loc = self._default_repo_location
if not my_loc and self.c: # pragma: no cover
# fallback until all config usage is removed.
my_loc = self.c.repo_location
cmd = ['vpython3', self.repo_resource('git_cl.py'), subcmd] + args
with self.m.context(cwd=self.m.context.cwd or my_loc):
return self.m.step(name, cmd, **kwargs)
def set_default_repo_location(self, path: Optional[Path]):
"""Sets the working directory where `git cl` will run, unless `cwd` from the
context module has been set.
If you set `path` to None, this will remove the default.
"""
self._default_repo_location = path
def get_description(self, patch_url=None, **kwargs):
"""DEPRECATED. Consider using gerrit.get_change_description instead."""
args = ['-d']

@ -8,7 +8,8 @@ from recipe_engine.config import config_item_context, ConfigGroup, BadConf
from recipe_engine.config import Single
from recipe_engine.config_types import Path
def BaseConfig(**_kwargs):
def BaseConfig(**_kwargs): # pragma: no cover
return ConfigGroup(
repo_location=Single(Path)
)
@ -16,7 +17,5 @@ def BaseConfig(**_kwargs):
config_ctx = config_item_context(BaseConfig)
@config_ctx()
def basic(c):
def basic(c): # pragma: no cover
pass

@ -3,11 +3,6 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from recipe_engine.config_types import Path
PYTHON_VERSION_COMPATIBILITY = 'PY2+3'
DEPS = [
'git_cl',
'recipe_engine/path',
@ -26,8 +21,7 @@ def RunSteps(api):
'bammmm', patch_url='https://code.review/123')
api.step('echo', ['echo', result.stdout.decode('utf-8')])
api.git_cl.set_config('basic')
api.git_cl.c.repo_location = api.path.mkdtemp('fakerepo')
api.git_cl.set_default_repo_location(api.path.mkdtemp('fakerepo'))
api.step(
'echo', ['echo', api.git_cl.get_description().stdout.decode('utf-8')])
@ -48,4 +42,3 @@ def GenTests(api):
'git_cl description (2)', stdout=api.raw_io.output(
'new description woo'))
)

Loading…
Cancel
Save