File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Expand file tree Collapse file tree 1 file changed +10
-7
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
5+ from urllib .parse import urlparse , urlunparse
66
77import requests
88from jupyterhub .services .auth import HubAuth
@@ -35,12 +35,15 @@ def main(argv=None):
3535
3636 # Read the env var JUPYTERHUB_SERVICE_URL and replace port in the URL
3737 # with free port that we found here
38- url = urlparse (os .environ .get ("JUPYTERHUB_SERVICE_URL" , "" ))
39- # Updated URL. We are effectively passing the port arg via env var
40- if url .hostname :
41- os .environ ["JUPYTERHUB_SERVICE_URL" ] = (
42- f"{ url .scheme } ://{ url .hostname } :{ port } { url .path } "
43- )
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 } " )
4447
4548 cmd_path = which (sys .argv [1 ])
4649 sys .argv = sys .argv [1 :]
You can’t perform that action at this time.
0 commit comments