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

Side by Side Diff: recipe_modules/python/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
OLDNEW
1 # Copyright 2013 The LUCI Authors. All rights reserved. 1 # Copyright 2013 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 import textwrap 5 import textwrap
6 6
7 from recipe_engine import config_types 7 from recipe_engine import config_types
8 from recipe_engine import recipe_api 8 from recipe_engine import recipe_api
9 9
10 class PythonApi(recipe_api.RecipeApi): 10 class PythonApi(recipe_api.RecipeApi):
(...skipping 13 matching lines...) Expand all
24 Python command. 24 Python command.
25 unbuffered (bool): If True, run Python in unbuffered mode. 25 unbuffered (bool): If True, run Python in unbuffered mode.
26 venv (None or False or True or Path): If True, run the script through 26 venv (None or False or True or Path): If True, run the script through
27 "vpython". This will, by default, probe the target script for a 27 "vpython". This will, by default, probe the target script for a
28 configured VirtualEnv and, failing that, use an empty VirtualEnv. If a 28 configured VirtualEnv and, failing that, use an empty VirtualEnv. If a
29 Path, this is a path to an explicit "vpython" VirtualEnv spec file to 29 Path, this is a path to an explicit "vpython" VirtualEnv spec file to
30 use. If False or None (default), the script will be run through the 30 use. If False or None (default), the script will be run through the
31 standard Python interpreter. 31 standard Python interpreter.
32 kwargs: Additional keyword arguments to forward to "step". 32 kwargs: Additional keyword arguments to forward to "step".
33 """ 33 """
34 env = self.m.context.env 34 env = {}
35 35
36 if venv: 36 if venv:
37 cmd = ['vpython'] 37 cmd = ['vpython']
38 if isinstance(venv, config_types.Path): 38 if isinstance(venv, config_types.Path):
39 cmd += ['-spec', venv] 39 cmd += ['-spec', venv]
40 else: 40 else:
41 cmd = ['python'] 41 cmd = ['python']
42 42
43 if unbuffered: 43 if unbuffered:
44 cmd.append('-u') 44 cmd.append('-u')
45 else: 45 else:
46 env['PYTHONUNBUFFERED'] = None 46 env['PYTHONUNBUFFERED'] = None
47 47
48 context = {}
49 if env:
50 context['env'] = env
51
52 cmd.append(script) 48 cmd.append(script)
53 with self.m.context(**context): 49 with self.m.context(env=env):
54 return self.m.step(name, cmd + list(args or []), **kwargs) 50 return self.m.step(name, cmd + list(args or []), **kwargs)
55 51
56 def inline(self, name, program, add_python_log=True, **kwargs): 52 def inline(self, name, program, add_python_log=True, **kwargs):
57 """Run an inline python program as a step. 53 """Run an inline python program as a step.
58 54
59 Program is output to a temp file and run when this step executes. 55 Program is output to a temp file and run when this step executes.
60 """ 56 """
61 program = textwrap.dedent(program) 57 program = textwrap.dedent(program)
62 compile(program, '<string>', 'exec', dont_inherit=1) 58 compile(program, '<string>', 'exec', dont_inherit=1)
63 59
(...skipping 21 matching lines...) Expand all
85 else: 81 else:
86 self.m.step.active_result.presentation.step_text = text 82 self.m.step.active_result.presentation.step_text = text
87 83
88 def succeeding_step(self, name, text, as_log=None): 84 def succeeding_step(self, name, text, as_log=None):
89 """Return a succeeding step (correctly recognized in expectations).""" 85 """Return a succeeding step (correctly recognized in expectations)."""
90 return self.result_step(name, text, 0, as_log=as_log) 86 return self.result_step(name, text, 0, as_log=as_log)
91 87
92 def failing_step(self, name, text, as_log=None): 88 def failing_step(self, name, text, as_log=None):
93 """Return a failing step (correctly recognized in expectations).""" 89 """Return a failing step (correctly recognized in expectations)."""
94 return self.result_step(name, text, 1, as_log=as_log) 90 return self.result_step(name, text, 1, as_log=as_log)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698