From c35d024b8d4b818e9bf09aee2afc7fa3caa4a0ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Arg=C3=BCelles?= Date: Tue, 5 Sep 2023 10:43:35 +0700 Subject: [PATCH] west: core: add search path argument to require() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow the runners to override the default search path, e.g. when provided through command line. The default is to search for the program binary on the system PATH. This is useful when the runner allows to optionally override the search path of the tool, in the case there are multiple versions or installations, and not necessarily the tools path are present in the system PATH environment variable. For example: `tool = self.require(tool_name, path=args.tool_path_override)` Signed-off-by: Manuel Argüelles --- scripts/west_commands/runners/core.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/west_commands/runners/core.py b/scripts/west_commands/runners/core.py index fa697fa66cf..fd21af0db5e 100644 --- a/scripts/west_commands/runners/core.py +++ b/scripts/west_commands/runners/core.py @@ -658,19 +658,21 @@ class ZephyrBinaryRunner(abc.ABC): in the order they appear on the command line.''' @staticmethod - def require(program: str) -> str: + def require(program: str, path: Optional[str] = None) -> str: '''Require that a program is installed before proceeding. :param program: name of the program that is required, or path to a program binary. + :param path: PATH where to search for the program binary. + By default check on the system PATH. If ``program`` is an absolute path to an existing program binary, this call succeeds. Otherwise, try to find the program - by name on the system PATH. + by name on the system PATH or in the given PATH, if provided. If the program can be found, its path is returned. Otherwise, raises MissingProgram.''' - ret = shutil.which(program) + ret = shutil.which(program, path=path) if ret is None: raise MissingProgram(program) return ret