Skip to content

Commit

Permalink
Merge pull request #267 from mahendrapaipuri/upgrade_jh_4
Browse files Browse the repository at this point in the history
Upgrade singleuser.py to JupyterHub 4
  • Loading branch information
minrk authored Mar 8, 2024
2 parents d75a5db + 050ae92 commit 2b4102a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion batchspawner/singleuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
from runpy import run_path
from shutil import which
from urllib.parse import urlparse, urlunparse

import requests
from jupyterhub.services.auth import HubAuth
Expand Down Expand Up @@ -32,8 +33,20 @@ def main(argv=None):
**kwargs,
)

# Read the env var JUPYTERHUB_SERVICE_URL and replace port in the URL
# with free port that we found here
# JUPYTERHUB_SERVICE_URL is added in JupyterHub 2.0
service_url_env = os.environ.get("JUPYTERHUB_SERVICE_URL", "")
if service_url_env:
url = urlparse(os.environ["JUPYTERHUB_SERVICE_URL"])
url = url._replace(netloc=f"{url.hostname}:{port}")
os.environ["JUPYTERHUB_SERVICE_URL"] = urlunparse(url)
else:
# JupyterHub < 2.0 specifies port on the command-line
sys.argv.append(f"--port={port}")

cmd_path = which(sys.argv[1])
sys.argv = sys.argv[1:] + [f"--port={port}"]
sys.argv = sys.argv[1:]
run_path(cmd_path, run_name="__main__")


Expand Down

0 comments on commit 2b4102a

Please sign in to comment.