Skip to content

Commit 7e42f21

Browse files
committed
feat: removed check_port and made command optional
1 parent 477e018 commit 7e42f21

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

jupyter_server_proxy/config.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
except ImportError:
1818
from .utils import Callable
1919

20-
def _make_serverproxy_handler(name, command, environment, timeout, absolute_url, port, check_port, mappath, request_headers_override, rewrite_response):
20+
def _make_serverproxy_handler(name, command, environment, timeout, absolute_url, port, mappath, request_headers_override, rewrite_response):
2121
"""
2222
Create a SuperviseAndProxyHandler subclass with given parameters
2323
"""
@@ -26,10 +26,10 @@ class _Proxy(SuperviseAndProxyHandler):
2626
def __init__(self, *args, **kwargs):
2727
super().__init__(*args, **kwargs)
2828
self.name = name
29+
self.command = command
2930
self.proxy_base = name
3031
self.absolute_url = absolute_url
3132
self.requested_port = port
32-
self.check_port = check_port
3333
self.mappath = mappath
3434
self.rewrite_response = rewrite_response
3535

@@ -63,7 +63,7 @@ def _realize_rendered_template(self, attribute):
6363
return self._render_template(attribute)
6464

6565
def get_cmd(self):
66-
return self._realize_rendered_template(command)
66+
return self._realize_rendered_template(self.command)
6767

6868
def get_env(self):
6969
return self._realize_rendered_template(environment)
@@ -115,20 +115,19 @@ def make_handlers(base_url, server_processes):
115115

116116
LauncherEntry = namedtuple('LauncherEntry', ['enabled', 'icon_path', 'title', 'path_info'])
117117
ServerProcess = namedtuple('ServerProcess', [
118-
'name', 'command', 'environment', 'timeout', 'absolute_url', 'port', 'check_port',
118+
'name', 'command', 'environment', 'timeout', 'absolute_url', 'port',
119119
'mappath', 'launcher_entry', 'new_browser_tab', 'request_headers_override', 'rewrite_response',
120120
])
121121

122122
def make_server_process(name, server_process_config, serverproxy_config):
123123
le = server_process_config.get('launcher_entry', {})
124124
return ServerProcess(
125125
name=name,
126-
command=server_process_config['command'],
126+
command=server_process_config.get('command', list()),
127127
environment=server_process_config.get('environment', {}),
128128
timeout=server_process_config.get('timeout', 5),
129129
absolute_url=server_process_config.get('absolute_url', False),
130130
port=server_process_config.get('port', 0),
131-
check_port=server_process_config.get('check_port', True),
132131
mappath=server_process_config.get('mappath', {}),
133132
launcher_entry=LauncherEntry(
134133
enabled=le.get('enabled', True),
@@ -155,12 +154,16 @@ class ServerProxy(Configurable):
155154
156155
Value should be a dictionary with the following keys:
157156
command
158-
A list of strings that should be the full command to be executed.
157+
An optional list of strings that should be the full command to be executed.
159158
The optional template arguments {{port}} and {{base_url}} will be substituted with the
160159
port the process should listen on and the base-url of the notebook.
161160
162161
Could also be a callable. It should return a list.
163162
163+
If the command is not specified or is an empty list, it is assumed the process is already
164+
running, therefore the port checking is skipped and the proxy is set up on the specified
165+
port.
166+
164167
environment
165168
A dictionary of environment variable mappings. As with the command
166169
traitlet, {{port}} and {{base_url}} will be substituted.
@@ -177,10 +180,6 @@ class ServerProxy(Configurable):
177180
port
178181
Set the port that the service will listen on. The default is to automatically select an unused port.
179182
180-
check_port
181-
Enable/Disable port availability check. If enabled and port is not available, the proxy will
182-
raise an exception. If disabled, the port availability check is skipped. Default is True.
183-
184183
mappath
185184
Map request paths to proxied paths.
186185
Either a dictionary of request paths to proxied paths,

jupyter_server_proxy/handlers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ class SuperviseAndProxyHandler(LocalProxyHandler):
558558
def __init__(self, *args, **kwargs):
559559
self.requested_port = 0
560560
self.mappath = {}
561-
self.check_port = True
561+
self.command = list()
562562
super().__init__(*args, **kwargs)
563563

564564
def initialize(self, state):
@@ -574,7 +574,7 @@ def port(self):
574574
Allocate either the requested port or a random empty port for use by
575575
application
576576
"""
577-
if 'port' not in self.state and self.check_port:
577+
if 'port' not in self.state and self.command:
578578
sock = socket.socket()
579579
sock.bind(('', self.requested_port))
580580
self.state['port'] = sock.getsockname()[1]

0 commit comments

Comments
 (0)