99from collections import namedtuple
1010from .utils import call_with_asked_args
1111
12- def _make_serverproxy_handler (name , command , environment , timeout , absolute_url ):
12+ def _make_serverproxy_handler (name , command , environment , timeout , absolute_url , port ):
1313 """
1414 Create a SuperviseAndProxyHandler subclass with given parameters
1515 """
@@ -20,6 +20,7 @@ def __init__(self, *args, **kwargs):
2020 self .name = name
2121 self .proxy_base = name
2222 self .absolute_url = absolute_url
23+ self .requested_port = port
2324
2425 @property
2526 def process_args (self ):
@@ -80,6 +81,7 @@ def make_handlers(base_url, server_processes):
8081 sp .environment ,
8182 sp .timeout ,
8283 sp .absolute_url ,
84+ sp .port ,
8385 )
8486 handlers .append ((
8587 ujoin (base_url , sp .name , r'(.*)' ), handler , dict (state = {}),
@@ -91,7 +93,7 @@ def make_handlers(base_url, server_processes):
9193
9294LauncherEntry = namedtuple ('LauncherEntry' , ['enabled' , 'icon_path' , 'title' ])
9395ServerProcess = namedtuple ('ServerProcess' , [
94- 'name' , 'command' , 'environment' , 'timeout' , 'absolute_url' , 'launcher_entry' ])
96+ 'name' , 'command' , 'environment' , 'timeout' , 'absolute_url' , 'port' , ' launcher_entry' ])
9597
9698def make_server_process (name , server_process_config ):
9799 le = server_process_config .get ('launcher_entry' , {})
@@ -101,6 +103,7 @@ def make_server_process(name, server_process_config):
101103 environment = server_process_config .get ('environment' , {}),
102104 timeout = server_process_config .get ('timeout' , 5 ),
103105 absolute_url = server_process_config .get ('absolute_url' , False ),
106+ port = server_process_config .get ('port' , 0 ),
104107 launcher_entry = LauncherEntry (
105108 enabled = le .get ('enabled' , True ),
106109 icon_path = le .get ('icon_path' ),
@@ -138,6 +141,9 @@ class ServerProxy(Configurable):
138141 Proxy requests default to being rewritten to '/'. If this is True,
139142 the absolute URL will be sent to the backend instead.
140143
144+ port
145+ Set the port that the service will listen on. The default is to automatically select an unused port.
146+
141147 launcher_entry
142148 A dictionary of various options for entries in classic notebook / jupyterlab launchers.
143149
0 commit comments