Skip to content

Commit fc55025

Browse files
Pass port arg via env var instead of CLI
jupyterhub-singleuser is an extension in JH 4 and it does not expect any CLI args. We need to pass the free port that we found in batchspawner singleuser script to jupyterhub-singleuser via `JUPYTERHUB_SERVICE_URL` env variable.
1 parent d5f9a0b commit fc55025

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

batchspawner/singleuser.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import sys
33

4+
from urllib.parse import urlparse
45
from runpy import run_path
56
from shutil import which
67

@@ -34,8 +35,15 @@ def main(argv=None):
3435
**kwargs,
3536
)
3637

38+
# Read the env var JUPYTERHUB_SERVICE_URL and replace port in the URL
39+
# with free port that we found here
40+
url = urlparse(os.environ.get("JUPYTERHUB_SERVICE_URL", ""))
41+
# Updated URL. We are effectively passing the port arg via env var
42+
if url.hostname:
43+
os.environ["JUPYTERHUB_SERVICE_URL"] = f"{url.scheme}://{url.hostname}:{port}{url.path}"
44+
3745
cmd_path = which(sys.argv[1])
38-
sys.argv = sys.argv[1:] + ["--port={}".format(port)]
46+
sys.argv = sys.argv[1:]
3947
run_path(cmd_path, run_name="__main__")
4048

4149

0 commit comments

Comments
 (0)