1
- from jupyterhub .singleuser import SingleUserNotebookApp
2
- from jupyterhub .utils import random_port , url_path_join
3
- from traitlets import default
1
+ import os
2
+ import sys
4
3
5
- class BatchSingleUserNotebookApp (SingleUserNotebookApp ):
6
- @default ('port' )
7
- def _port (self ):
8
- return random_port ()
4
+ from runpy import run_path
5
+ from shutil import which
9
6
10
- def start (self ):
11
- # Send Notebook app's port number to remote Spawner
12
- self .hub_auth ._api_request (method = 'POST' ,
13
- url = url_path_join (self .hub_api_url , 'batchspawner' ),
14
- json = {'port' : self .port })
15
- super ().start ()
7
+ from jupyterhub .utils import random_port , url_path_join
8
+ from jupyterhub .services .auth import HubAuth
16
9
17
10
def main (argv = None ):
18
- return BatchSingleUserNotebookApp .launch_instance (argv )
11
+ port = random_port ()
12
+ hub_auth = HubAuth ()
13
+ hub_auth .client_ca = os .environ .get ('JUPYTERHUB_SSL_CLIENT_CA' , '' )
14
+ hub_auth .certfile = os .environ .get ('JUPYTERHUB_SSL_CERTFILE' , '' )
15
+ hub_auth .keyfile = os .environ .get ('JUPYTERHUB_SSL_KEYFILE' , '' )
16
+ hub_auth ._api_request (method = 'POST' ,
17
+ url = url_path_join (hub_auth .api_url , 'batchspawner' ),
18
+ json = {'port' : port })
19
+
20
+ cmd_path = which (sys .argv [1 ])
21
+ sys .argv = sys .argv [1 :] + ['--port={}' .format (port )]
22
+ run_path (cmd_path , run_name = "__main__" )
19
23
20
24
if __name__ == "__main__" :
21
25
main ()
0 commit comments