| # Copyright 2022 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| from recipe_engine import recipe_api |
| |
| |
| class Python3Api(recipe_api.RecipeApi): |
| """API for running scripts with python3.""" |
| |
| def __call__(self, name, args, **kwargs): |
| """Run a script using python3. |
| |
| It's generally preferred for each project to pin its own version of |
| Python, so this should only be used for running resources scripts from |
| lightweight CI-only recipes, or for testing projects for which it's |
| infeasible to pin a Python version. |
| |
| Args: |
| name (str): Name of the step. |
| args (seq of string): Positional arguments to python. |
| **kwargs (dict): Passed through to api.step(). |
| """ |
| cmd = [self._python3_path] |
| cmd.extend(args) |
| return self.m.step(name, cmd, **kwargs) |
| |
| @property |
| def _python3_path(self): |
| exe_name = "bin/python3" |
| if self.m.platform.is_win: |
| exe_name += ".exe" |
| return self.m.ensure_tool( |
| "cpython3", self.resource("tool_manifest.json"), executable_path=exe_name |
| ) |