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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | recipe_modules/context/tests/env.expected/basic.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2017 The LUCI Authors. All rights reserved. 1 # Copyright 2017 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0 2 # Use of this source code is governed under the Apache License, Version 2.0
3 # that can be found in the LICENSE file. 3 # that can be found in the LICENSE file.
4 4
5 """The context module provides APIs for manipulating a few pieces of 'ambient' 5 """The context module provides APIs for manipulating a few pieces of 'ambient'
6 data that affect how steps are run: 6 data that affect how steps are run:
7 cwd - The current working directory. 7 cwd - The current working directory.
8 env - The environment variables. 8 env - The environment variables.
9 infra_step - Whether or not failures should be treated as infrastructure 9 infra_step - Whether or not failures should be treated as infrastructure
10 failures vs. normal failures. 10 failures vs. normal failures.
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 """Returns the current working directory that steps will run in. 191 """Returns the current working directory that steps will run in.
192 192
193 Returns (Path|None) - The current working directory. A value of None is 193 Returns (Path|None) - The current working directory. A value of None is
194 equivalent to api.path['start_dir'], though only occurs if no cwd has been 194 equivalent to api.path['start_dir'], though only occurs if no cwd has been
195 set (e.g. in the outermost context of RunSteps). 195 set (e.g. in the outermost context of RunSteps).
196 """ 196 """
197 return self._cwd[-1] 197 return self._cwd[-1]
198 198
199 @property 199 @property
200 def env(self): 200 def env(self):
201 """Returns modifications to the environment. 201 """Returns string modifications to the environment.
202 202
203 By default this is empty; There's no facility to observe the program's 203 By default this is empty; There's no facility to observe the program's
204 startup environment. If you want to pass data to the recipe, it should be 204 startup environment. If you want to pass data to the recipe, it should be
205 done with properties. 205 done with properties.
206 206
207 This will return the string modifications made to the environment. For
208 prefix modifications, use "env_prefixes".
209
207 Returns (dict) - The env-key -> value mapping of current environment 210 Returns (dict) - The env-key -> value mapping of current environment
208 modifications. 211 modifications.
209 """ 212 """
210 # TODO(iannucci): store env in an immutable way to avoid excessive copies. 213 # TODO(iannucci): store env in an immutable way to avoid excessive copies.
211 # TODO(iannucci): handle case-insensitive keys on windows 214 # TODO(iannucci): handle case-insensitive keys on windows
212 def parts(ev): 215 return {k: v.value for k, v in self._env[-1].iteritems()}
213 for p in ev.prefixes:
214 yield str(p)
215 if ev.value:
216 yield ev.value
217 216
218 ret = {} 217 @property
219 for k, ev in self._env[-1].iteritems(): 218 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
220 if ev.value is None: 219 """Returns Path prefix modifications to the environment.
221 ret[k] = None
222 else:
223 ret[k] = self.m.path.pathsep.join(parts(ev))
224 220
225 return ret 221 This will return a mapping of environment key to Path tuple for Path
222 prefixes registered with the environment.
223
224 Returns (dict) - The env-key -> value(Path) mapping of current environment
225 prefix modifications.
226 """
227 return {k: v.prefixes for k, v in self._env[-1].iteritems()
228 if v.prefixes}
226 229
227 @property 230 @property
228 def infra_step(self): 231 def infra_step(self):
229 """Returns the current value of the infra_step setting. 232 """Returns the current value of the infra_step setting.
230 233
231 Returns (bool) - True iff steps are currently considered infra steps. 234 Returns (bool) - True iff steps are currently considered infra steps.
232 """ 235 """
233 return self._infra_step[-1] 236 return self._infra_step[-1]
234 237
235 @property 238 @property
(...skipping 21 matching lines...) Expand all
257 the beginning of an environment variable. 260 the beginning of an environment variable.
258 261
259 Each path in paths is added, in order, as a prefix to the environment 262 Each path in paths is added, in order, as a prefix to the environment
260 variable, delimited by the OS path separator. This can be used for 263 variable, delimited by the OS path separator. This can be used for
261 easy manipulation of path environment variables such as PATH and PYTHONPATH. 264 easy manipulation of path environment variables such as PATH and PYTHONPATH.
262 265
263 Args: 266 Args:
264 paths (...Path): The list of paths to prefix. 267 paths (...Path): The list of paths to prefix.
265 """ 268 """
266 for i, path in enumerate(paths): 269 for i, path in enumerate(paths):
267 check_type('path element %d' % (i,), path, Path) 270 check_type('path element %d' % (i,), path, (Path, str))
268 return _EnvPathComponent(paths=paths) 271 return _EnvPathComponent(paths=paths)
OLDNEW
« 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