Add fixed singleuser command script

This commit is contained in:
Benoît Seignovert 2024-02-06 16:21:28 +01:00
parent 3cac72ee29
commit 29739c792e
Signed by: Benoît Seignovert
GPG key ID: F5D8895227D18A0B
2 changed files with 41 additions and 0 deletions

View file

@ -8,6 +8,9 @@ readme = "README.md"
repository = "https://gitlab.univ-nantes.fr/glicid/jupyter/spawner"
packages = [{ include = "glicid_spawner", from = "src"}]
[tool.poetry.scripts]
glicid-spawner-singleuser = 'glicid_spawner.singleuser:main'
[tool.poetry.plugins."jupyterhub.spawners"]
glicid-spawner = 'glicid_spawner:GlicidSpawner'

View file

@ -0,0 +1,38 @@
"""Patched JupyterHub singleuser command script.
Fix based on batchspawner#250:
https://github.com/jupyterhub/batchspawner/pull/250
The Hub API should use an async call.
"""
import asyncio
import json
import sys
from runpy import run_path
from shutil import which
from jupyterhub.services.auth import HubAuth
from jupyterhub.utils import random_port, url_path_join
def main(argv=None):
port = random_port()
hub_auth = HubAuth()
asyncio.run(
hub_auth._api_request(
method='POST',
url=url_path_join(hub_auth.api_url, 'batchspawner'),
body=json.dumps({'port': port}),
)
)
cmd_path = which(sys.argv[1])
sys.argv = sys.argv[1:] + [f'--port={port}']
run_path(cmd_path, run_name='__main__')
if __name__ == '__main__':
main()