File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change 22import sys
33from runpy import run_path
44from shutil import which
5+ from urllib .parse import urlparse , urlunparse
56
67import requests
78from jupyterhub .services .auth import HubAuth
@@ -32,8 +33,20 @@ def main(argv=None):
3233 ** kwargs ,
3334 )
3435
36+ # Read the env var JUPYTERHUB_SERVICE_URL and replace port in the URL
37+ # with free port that we found here
38+ # JUPYTERHUB_SERVICE_URL is added in JupyterHub 2.0
39+ service_url_env = os .environ .get ("JUPYTERHUB_SERVICE_URL" , "" )
40+ if service_url_env :
41+ url = urlparse (os .environ ["JUPYTERHUB_SERVICE_URL" ])
42+ url = url ._replace (netloc = f"{ url .hostname } :{ port } " )
43+ os .environ ["JUPYTERHUB_SERVICE_URL" ] = urlunparse (url )
44+ else :
45+ # JupyterHub < 2.0 specifies port on the command-line
46+ sys .argv .append (f"--port={ port } " )
47+
3548 cmd_path = which (sys .argv [1 ])
36- sys .argv = sys .argv [1 :] + [ f"--port= { port } " ]
49+ sys .argv = sys .argv [1 :]
3750 run_path (cmd_path , run_name = "__main__" )
3851
3952
You can’t perform that action at this time.
0 commit comments