Skip to content

Commit 1c93807

Browse files
author
Łukasz Stelmach
committed
agentwrapper: Allow specyfing Python executable
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 <l.stelmach@samsung.com>
1 parent d4dafb9 commit 1c93807

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

doc/man/client.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ LG_AGENT_PREFIX
8080
Add a prefix to ``.labgrid_agent_{agent_hash}.py`` allowing specification for
8181
where on the exporter it should be uploaded to.
8282

83+
LG_AGENT_PYTHON
84+
~~~~~~~~~~~~~~~
85+
Specify python executable other the the default ``python3``. By pointing
86+
to an executable in a particular virtual environment, use this environment
87+
and its packages to run the agent and any agent-wrapped code.
88+
8389
Matches
8490
-------
8591
Match patterns are used to assign a resource to a specific place. The format is:

labgrid/util/agentwrapper.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def __init__(self, host=None):
4747
os.path.abspath(os.path.dirname(__file__)),
4848
'agent.py')
4949
agent_prefix = os.environ.get("LG_AGENT_PREFIX", "")
50+
python_exe = os.environ.get("LG_AGENT_PYTHON", "python3")
5051
if host:
5152
# copy agent.py and run via ssh
5253
with open(agent, 'rb') as agent_fd:
@@ -60,15 +61,15 @@ def __init__(self, host=None):
6061
f'{host}:{agent_remote}'],
6162
)
6263
self.agent = subprocess.Popen(
63-
ssh_opts + [host, '--', 'python3', agent_remote],
64+
ssh_opts + [host, '--', python_exe, agent_remote],
6465
stdin=subprocess.PIPE,
6566
stdout=subprocess.PIPE,
6667
start_new_session=True,
6768
)
6869
else:
6970
# run locally
7071
self.agent = subprocess.Popen(
71-
['python3', agent],
72+
[python_exe, agent],
7273
stdin=subprocess.PIPE,
7374
stdout=subprocess.PIPE,
7475
start_new_session=True,

man/labgrid-client.1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,11 @@ unspecified, defaults to 30 seconds.
11321132
.sp
11331133
Add a prefix to \fB\&.labgrid_agent_{agent_hash}.py\fP allowing specification for
11341134
where on the exporter it should be uploaded to.
1135+
.SS LG_AGENT_PYTHON
1136+
.sp
1137+
Specify python executable other the the default \fBpython3\fP\&. By pointing
1138+
to an executable in a particular virtual environment, use this environment
1139+
and its packages to run the agent and any agent\-wrapped code.
11351140
.SH MATCHES
11361141
.sp
11371142
Match patterns are used to assign a resource to a specific place. The format is:

0 commit comments

Comments
 (0)