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

Unified Diff: recipe_modules/python/api.py

Issue 2875823002: Add vpython support to Python recipe module. (Closed)
Patch Set: rebase 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/unittests/run_test.py ('k') | recipe_modules/python/example.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: recipe_modules/python/api.py
diff --git a/recipe_modules/python/api.py b/recipe_modules/python/api.py
index 7d934679c09bee8f08d7674164044242e13918fe..2f0d03f50623aeaecaab56eba11e555df9886b71 100644
--- a/recipe_modules/python/api.py
+++ b/recipe_modules/python/api.py
@@ -2,15 +2,44 @@
# Use of this source code is governed under the Apache License, Version 2.0
# that can be found in the LICENSE file.
-from recipe_engine import recipe_api
-
import textwrap
+from recipe_engine import config_types
+from recipe_engine import recipe_api
+
class PythonApi(recipe_api.RecipeApi):
- def __call__(self, name, script, args=None, unbuffered=True, **kwargs):
- """Return a step to run a python script with arguments."""
+ def __call__(self, name, script, args=None, unbuffered=True, venv=None,
+ **kwargs):
+ """Return a step to run a python script with arguments.
+
+ TODO: We should just use a single "args" list. Having "script"
+ separate but required/first leads to weird things like:
+ (... script='-m', args=['module'])
+
+ Args:
+ name (str): The name of the step.
+ script (str or Path): The Path of the script to run, or the first
+ command-line argument to pass to Python.
+ args (list or None): If not None, additional arguments to pass to the
+ Python command.
+ unbuffered (bool): If True, run Python in unbuffered mode.
+ venv (None or False or True or Path): If True, run the script through
+ "vpython". This will, by default, probe the target script for a
+ configured VirtualEnv and, failing that, use an empty VirtualEnv. If a
+ Path, this is a path to an explicit "vpython" VirtualEnv spec file to
+ use. If False or None (default), the script will be run through the
+ standard Python interpreter.
+ kwargs: Additional keyword arguments to forward to "step".
+ """
env = self.m.context.env
- cmd = ['python']
+
+ if venv:
+ cmd = ['vpython']
+ if isinstance(venv, config_types.Path):
+ cmd += ['-spec', venv]
+ else:
+ cmd = ['python']
+
if unbuffered:
cmd.append('-u')
else:
« no previous file with comments | « recipe_engine/unittests/run_test.py ('k') | recipe_modules/python/example.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698