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

Unified Diff: recipe_modules/context/api.py

Issue 2933473002: [context] Split "env" values and prefixes. (Closed)
Patch Set: Created 3 years, 6 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 | « no previous file | recipe_modules/context/tests/env.expected/basic.json » ('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 4f9b9d4beaebfc1f2250b3e76d99c333d1f07eb4..619b96e6a6883cfd24de92dbe2c26bc701c941a3 100644
--- a/recipe_modules/context/api.py
+++ b/recipe_modules/context/api.py
@@ -198,31 +198,34 @@ class ContextApi(RecipeApi):
@property
def env(self):
- """Returns modifications to the environment.
+ """Returns string modifications to the environment.
By default this is empty; There's no facility to observe the program's
startup environment. If you want to pass data to the recipe, it should be
done with properties.
+ This will return the string modifications made to the environment. For
+ prefix modifications, use "env_prefixes".
+
Returns (dict) - The env-key -> value mapping of current environment
modifications.
"""
# TODO(iannucci): store env in an immutable way to avoid excessive copies.
# TODO(iannucci): handle case-insensitive keys on windows
- def parts(ev):
- for p in ev.prefixes:
- yield str(p)
- if ev.value:
- yield ev.value
-
- ret = {}
- for k, ev in self._env[-1].iteritems():
- if ev.value is None:
- ret[k] = None
- else:
- ret[k] = self.m.path.pathsep.join(parts(ev))
+ return {k: v.value for k, v in self._env[-1].iteritems()}
+
+ @property
+ def env_prefixes(self):
iannucci 2017/06/09 04:47:45 I was actually thinking of storing these as separa
dnj 2017/06/09 04:50:33 I think that this might be a better API - less thi
+ """Returns Path prefix modifications to the environment.
+
+ This will return a mapping of environment key to Path tuple for Path
+ prefixes registered with the environment.
- return ret
+ Returns (dict) - The env-key -> value(Path) mapping of current environment
+ prefix modifications.
+ """
+ return {k: v.prefixes for k, v in self._env[-1].iteritems()
+ if v.prefixes}
@property
def infra_step(self):
@@ -264,5 +267,5 @@ class ContextApi(RecipeApi):
paths (...Path): The list of paths to prefix.
"""
for i, path in enumerate(paths):
- check_type('path element %d' % (i,), path, Path)
+ check_type('path element %d' % (i,), path, (Path, str))
return _EnvPathComponent(paths=paths)
« no previous file with comments | « no previous file | recipe_modules/context/tests/env.expected/basic.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698