diff --git a/recipes/README.recipes.md b/recipes/README.recipes.md index 7736ceaad..999a117c7 100644 --- a/recipes/README.recipes.md +++ b/recipes/README.recipes.md @@ -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]):** -— **def [get\_description](/recipes/recipe_modules/git_cl/api.py#23)(self, patch_url=None, \*\*kwargs):** +— **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. *** -— **def [issue](/recipes/recipe_modules/git_cl/api.py#48)(self, \*\*kwargs):** +— **def [issue](/recipes/recipe_modules/git_cl/api.py#64)(self, \*\*kwargs):** -— **def [set\_description](/recipes/recipe_modules/git_cl/api.py#31)(self, description, patch_url=None, \*\*kwargs):** +— **def [set\_default\_repo\_location](/recipes/recipe_modules/git_cl/api.py#31)(self, path: Optional[Path]):** -— **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. + +— **def [set\_description](/recipes/recipe_modules/git_cl/api.py#47)(self, description, patch_url=None, \*\*kwargs):** + +— **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: — **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] -— **def [RunSteps](/recipes/recipe_modules/git_cl/examples/full.py#19)(api):** +— **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] diff --git a/recipes/recipe_modules/git_cl/api.py b/recipes/recipe_modules/git_cl/api.py index e9cb12dfe..e6db4d734 100644 --- a/recipes/recipe_modules/git_cl/api.py +++ b/recipes/recipe_modules/git_cl/api.py @@ -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'] diff --git a/recipes/recipe_modules/git_cl/config.py b/recipes/recipe_modules/git_cl/config.py index 70a96e7e2..30ccfba9d 100644 --- a/recipes/recipe_modules/git_cl/config.py +++ b/recipes/recipe_modules/git_cl/config.py @@ -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 - - diff --git a/recipes/recipe_modules/git_cl/examples/full.py b/recipes/recipe_modules/git_cl/examples/full.py index da4e8f51a..b39418037 100644 --- a/recipes/recipe_modules/git_cl/examples/full.py +++ b/recipes/recipe_modules/git_cl/examples/full.py @@ -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')) ) -