From ea0079d1eede6dd12facffe4d724eeb1ed88d75a Mon Sep 17 00:00:00 2001 From: Andy Fisher <4552674+afisher1@users.noreply.github.com> Date: Thu, 26 Dec 2024 02:33:52 -0800 Subject: [PATCH] Fix for HELICS runner spawning federates in virtual environments (#105) * Adding fix for issue 104 * Committing suggest use of shutil.which instead of sys.executable. * f string embedded quote correction --- helics/cli.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/helics/cli.py b/helics/cli.py index 9ef72f84..8ae776f6 100644 --- a/helics/cli.py +++ b/helics/cli.py @@ -13,6 +13,7 @@ import platform import urllib.request import logging +import shutil from ._version import __version__ from .status_checker import CheckStatusThread @@ -305,8 +306,14 @@ def run(path, silent, connect_server, no_log_files, no_kill_on_error): if "env" in f: for k, v in f["env"].items(): env[k] = v + p_args = shlex.split(f["exec"]) + p_args[0] = shutil.which(p_args[0]) + if p_args[0] is None: + raise click.ClickException("UnrecognizedCommandError: The command specified in exec string is not a " + "recognized command in the system. The user provided exec string is " + f"{f['exec']}.") p = subprocess.Popen( - shlex.split(f["exec"]), + p_args, cwd=os.path.abspath(os.path.expanduser(directory)), stdout=o.file, stderr=o.file,