From af39ced894199255c7a2997aa3ec877535ef48d8 Mon Sep 17 00:00:00 2001 From: Nicolas VINCENT Date: Fri, 24 May 2024 11:35:08 +0200 Subject: [PATCH] agent: add argument to specify python virutal env When using agentwrapper, the python packages used are the one installed on the machine. This commit add an argument to specify the path to a virtual env which will be used by the agent. Signed-off-by: Nicolas VINCENT --- labgrid/util/agentwrapper.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/labgrid/util/agentwrapper.py b/labgrid/util/agentwrapper.py index fd23a4031..b40cda1e8 100644 --- a/labgrid/util/agentwrapper.py +++ b/labgrid/util/agentwrapper.py @@ -38,7 +38,7 @@ def __getattr__(self, name): class AgentWrapper: - def __init__(self, host=None): + def __init__(self, host=None, pyvirtenv=None): self.agent = None self.loaded = {} self.logger = logging.getLogger(f"ResourceExport({host})") @@ -58,8 +58,12 @@ def __init__(self, host=None): ['rsync', '-e', ' '.join(ssh_opts), '-tq', agent, f'{host}:{agent_remote}'], ) + select_virtenv = [] + if pyvirtenv is not None: + select_virtenv = f'source {pyvirtenv}/bin/activate &&'.split() + cmd = select_virtenv + ['python3', agent_remote] self.agent = subprocess.Popen( - ssh_opts + [host, '--', 'python3', agent_remote], + ssh_opts + [host, '--'] + cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, start_new_session=True,