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

Side by Side Diff: recipe_modules/python/api.py

Issue 2875823002: Add vpython support to Python recipe module. (Closed)
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « no previous file | recipe_modules/python/example.py » ('j') | recipe_modules/python/example.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
6
7 from recipe_engine import config_types
5 from recipe_engine import recipe_api 8 from recipe_engine import recipe_api
6 9
7 import textwrap 10 class PythonApi(recipe_api.RecipeApi):
11 def __call__(self, name, script, args=None, unbuffered=True, venv=None,
12 **kwargs):
13 """Return a step to run a python script with arguments.
8 14
9 class PythonApi(recipe_api.RecipeApi): 15 Args:
10 def __call__(self, name, script, args=None, unbuffered=True, **kwargs): 16 name (str): The name of the step.
11 """Return a step to run a python script with arguments.""" 17 script (str): The name of the script to run (or the first command-line
iannucci 2017/05/10 22:46:14 Path also, TODO: wtf
18 argument to pass to Python)
19 args (list or None): If not None, additional arguments to pass to the
20 Python command.
21 unbuffered (bool): If True, run Python in unbuffered mode.
22 venv (None or False or True or Path): If True, run the script through
23 "vpython". This will, by default, probe the target script for a
24 configured VirtualEnv and, failing that, use an empty VirtualEnv. If a
25 Path, this is a path to an explicit "vpython" VirtualEnv spec file to
26 use. If False or None (default), the script will be run through the
27 standard Python interpreter.
28 kwargs: Additional keyword arguments to forward to "step".
29 """
12 env = self.m.step.get_from_context('env', {}) 30 env = self.m.step.get_from_context('env', {})
13 cmd = ['python'] 31
32 if venv:
33 cmd = ['vpython']
34 if isinstance(venv, config_types.Path):
35 cmd += ['-spec', venv]
36 else:
37 cmd = ['python']
38
14 if unbuffered: 39 if unbuffered:
15 cmd.append('-u') 40 cmd.append('-u')
16 else: 41 else:
17 env['PYTHONUNBUFFERED'] = None 42 env['PYTHONUNBUFFERED'] = None
18 43
19 context = {} 44 context = {}
20 if env: 45 if env:
21 context['env'] = env 46 context['env'] = env
22 47
23 cmd.append(script) 48 cmd.append(script)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 else: 81 else:
57 self.m.step.active_result.presentation.step_text = text 82 self.m.step.active_result.presentation.step_text = text
58 83
59 def succeeding_step(self, name, text, as_log=None): 84 def succeeding_step(self, name, text, as_log=None):
60 """Return a succeeding step (correctly recognized in expectations).""" 85 """Return a succeeding step (correctly recognized in expectations)."""
61 return self.result_step(name, text, 0, as_log=as_log) 86 return self.result_step(name, text, 0, as_log=as_log)
62 87
63 def failing_step(self, name, text, as_log=None): 88 def failing_step(self, name, text, as_log=None):
64 """Return a failing step (correctly recognized in expectations).""" 89 """Return a failing step (correctly recognized in expectations)."""
65 return self.result_step(name, text, 1, as_log=as_log) 90 return self.result_step(name, text, 1, as_log=as_log)
OLDNEW
« no previous file with comments | « no previous file | recipe_modules/python/example.py » ('j') | recipe_modules/python/example.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698