From ddcb2ca8723fdb00bf56549e56ffc8f7c884d509 Mon Sep 17 00:00:00 2001
From: Thomas Kluyver <thomas@kluyver.me.uk>
Date: Tue, 9 Jan 2024 14:40:51 +0000
Subject: [PATCH] Webservice: add environment bin/ to PATH if not already there

---
 webservice/webservice.py | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/webservice/webservice.py b/webservice/webservice.py
index 0652255f0..499e8061f 100644
--- a/webservice/webservice.py
+++ b/webservice/webservice.py
@@ -1522,6 +1522,14 @@ def main(argv: Optional[List[str]] = None):
         format=fmt
     )
 
+    # Ensure that subprocesses (to launch calibration) are launched with the
+    # venv where this is installed, even if it was not activated in a shell.
+    cmd_path = os.environ.get('PATH', os.defpath).split(os.pathsep)
+    my_env_bin = os.path.dirname(sys.executable)
+    if my_env_bin not in cmd_path:
+        logging.info("Adding %s to PATH", my_env_bin)
+        os.environ['PATH'] = os.pathsep.join([my_env_bin] + cmd_path)
+
     # Launch the ZMQ server to handle requests for calibration
     server = ActionsServer(config, mode)
     loop = asyncio.get_event_loop()
-- 
GitLab