From 5772c7e93d30ca6a567b6c05ef0f3f70ab3fb6c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Stelmach?= Date: Fri, 14 Nov 2025 15:30:48 +0100 Subject: [PATCH] agentwrapper: Allow specyfing Python executable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enable users to choose which Python executable to use to run the agent by setting LG_AGENT_PYTHON environment variable. This is necessary when a remote labgrid runs in a virtual environment which provide packages, or their versions, not available in the system installation of Python. Signed-off-by: Ɓukasz Stelmach --- doc/man/client.rst | 6 ++++++ labgrid/util/agentwrapper.py | 5 +++-- man/labgrid-client.1 | 5 +++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/doc/man/client.rst b/doc/man/client.rst index 309e36365..3b0491513 100644 --- a/doc/man/client.rst +++ b/doc/man/client.rst @@ -80,6 +80,12 @@ LG_AGENT_PREFIX Add a prefix to ``.labgrid_agent_{agent_hash}.py`` allowing specification for where on the exporter it should be uploaded to. +LG_AGENT_PYTHON +~~~~~~~~~~~~~~~ +Specify python executable other the the default ``python3``. By pointing +to an executable in a particular virtual environment, use this environment +and its packages to run the agent and any agent-wrapped code. + Matches ------- Match patterns are used to assign a resource to a specific place. The format is: diff --git a/labgrid/util/agentwrapper.py b/labgrid/util/agentwrapper.py index f505b861d..43b81f99d 100644 --- a/labgrid/util/agentwrapper.py +++ b/labgrid/util/agentwrapper.py @@ -47,6 +47,7 @@ def __init__(self, host=None): os.path.abspath(os.path.dirname(__file__)), 'agent.py') agent_prefix = os.environ.get("LG_AGENT_PREFIX", "") + python_exe = os.environ.get("LG_AGENT_PYTHON", "python3") if host: # copy agent.py and run via ssh with open(agent, 'rb') as agent_fd: @@ -60,7 +61,7 @@ def __init__(self, host=None): f'{host}:{agent_remote}'], ) self.agent = subprocess.Popen( - ssh_opts + [host, '--', 'python3', agent_remote], + ssh_opts + [host, '--', python_exe, agent_remote], stdin=subprocess.PIPE, stdout=subprocess.PIPE, start_new_session=True, @@ -68,7 +69,7 @@ def __init__(self, host=None): else: # run locally self.agent = subprocess.Popen( - ['python3', agent], + [python_exe, agent], stdin=subprocess.PIPE, stdout=subprocess.PIPE, start_new_session=True, diff --git a/man/labgrid-client.1 b/man/labgrid-client.1 index fdc62be72..f2f90c110 100644 --- a/man/labgrid-client.1 +++ b/man/labgrid-client.1 @@ -1132,6 +1132,11 @@ unspecified, defaults to 30 seconds. .sp Add a prefix to \fB\&.labgrid_agent_{agent_hash}.py\fP allowing specification for where on the exporter it should be uploaded to. +.SS LG_AGENT_PYTHON +.sp +Specify python executable other the the default \fBpython3\fP\&. By pointing +to an executable in a particular virtual environment, use this environment +and its packages to run the agent and any agent\-wrapped code. .SH MATCHES .sp Match patterns are used to assign a resource to a specific place. The format is: