Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade singleuser.py to JupyterHub 4 #267

Merged
merged 5 commits into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading