Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(961)

Unified Diff: recipe_modules/context/api.py

Issue 2913203002: [step_runner] run _merge_envs in simulation too. (Closed)
Patch Set: quotes and comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « recipe_engine/step_runner.py ('k') | recipe_modules/context/examples/full.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: recipe_modules/context/api.py
diff --git a/recipe_modules/context/api.py b/recipe_modules/context/api.py
index de7075670061fff5f591ada696c4515c01121531..e99dbe3c7706a49fa6a605dd70623a19fec4d63e 100644
--- a/recipe_modules/context/api.py
+++ b/recipe_modules/context/api.py
@@ -25,6 +25,7 @@ Example:
"""
+import collections
import copy
from contextlib import contextmanager
@@ -137,8 +138,27 @@ class ContextApi(RecipeApi):
check_type('env', env, dict)
# strify everything except None in the env to allow for ints, Paths, etc.
# None has special meaning (i.e. "delete this env key")
- kwargs['env'] = {str(k): (str(v) if v is not None else None)
- for k, v in env.iteritems()}
+ new_env = {}
+ for k, v in env.iteritems():
+ k = str(k)
+ if v is not None:
+ v = str(v)
+ try:
+ # This odd little piece of code does the following:
+ # * add a bogus dictionary format %(foo)s to v. This forces % into
+ # 'dictionary lookup' mode
+ # * format the result with a defaultdict. This allows all
+ # `%(key)s` format lookups to succeed, but any sequential `%s`
+ # lookups to fail.
+ # If the string contains any accidental sequential lookups, this
+ # will raise an exception. If not, then this is a pluasible format
+ # string.
+ ('%(foo)s'+v) % collections.defaultdict(str)
+ except Exception:
+ raise ValueError(('Invalid %%-formatting parameter in envvar, '
+ 'only %%(ENVVAR)s allowed: %r') % (v,))
+ new_env[k] = v
+ kwargs['env'] = new_env
if not kwargs:
yield
« no previous file with comments | « recipe_engine/step_runner.py ('k') | recipe_modules/context/examples/full.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698