Skip to content

Commit 05df15b

Browse files
committed
Remove unnecessary traitlets config values
1 parent 53c3a00 commit 05df15b

File tree

2 files changed

+37
-18
lines changed

2 files changed

+37
-18
lines changed

jupyter_server_proxy/__init__.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from ._version import __version__ # noqa
44
from .api import IconHandler, ServersInfoHandler
55
from .config import ServerProxy as ServerProxyConfig
6-
from .config import get_entrypoint_server_processes, make_handlers, make_server_process
6+
from .config import get_entrypoint_server_processes, make_handlers
77
from .handlers import setup_handlers
88

99

@@ -41,11 +41,8 @@ def _load_jupyter_server_extension(nbapp):
4141
base_url = nbapp.web_app.settings["base_url"]
4242
serverproxy_config = ServerProxyConfig(parent=nbapp)
4343

44-
server_processes = [
45-
make_server_process(name, server_process_config, serverproxy_config)
46-
for name, server_process_config in serverproxy_config.servers.items()
47-
]
48-
server_processes += get_entrypoint_server_processes(serverproxy_config)
44+
server_processes = list(serverproxy_config.servers.values())
45+
server_processes += get_entrypoint_server_processes()
4946
server_handlers = make_handlers(base_url, server_processes)
5047
nbapp.web_app.add_handlers(".*", server_handlers)
5148

jupyter_server_proxy/config.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
Callable,
2020
Dict,
2121
Float,
22+
HasTraits,
2223
Instance,
2324
Int,
2425
List,
@@ -35,7 +36,7 @@
3536
from .rawsocket import RawSocketHandler, SuperviseAndRawSocketHandler
3637

3738

38-
class LauncherEntry(Configurable):
39+
class LauncherEntry(HasTraits):
3940
enabled = Bool(
4041
True,
4142
help="""
@@ -151,9 +152,9 @@ class ServerProcess(Configurable):
151152
[Instance(LauncherEntry), Dict()],
152153
allow_none=False,
153154
help="""
154-
A dictionary of various options for entries in classic notebook / jupyterlab launchers.
155+
Specify various options for entries in classic notebook / jupyterlab launchers.
155156
156-
Keys recognized are:
157+
Must be an instance of ``LauncherEntry`` or a dictionary with the following keys:
157158
158159
``enabled``
159160
Set to True (default) to make an entry in the launchers. Set to False to have no
@@ -178,9 +179,14 @@ class ServerProcess(Configurable):
178179

179180
@validate("launcher_entry")
180181
def _validate_launcher_entry(self, proposal):
181-
kwargs = {"title": self.name, "path_info": self.name + "/"}
182-
kwargs.update(proposal["value"])
183-
return LauncherEntry(**kwargs)
182+
if isinstance(proposal["value"], LauncherEntry):
183+
proposal["value"].title = self.name
184+
proposal["value"].path_info = self.name + "/"
185+
return proposal["value"]
186+
else:
187+
kwargs = {"title": self.name, "path_info": self.name + "/"}
188+
kwargs.update(proposal["value"])
189+
return LauncherEntry(**kwargs)
184190

185191
@default("launcher_entry")
186192
def _default_launcher_entry(self):
@@ -341,17 +347,17 @@ def get_timeout(self):
341347
return _Proxy, proxy_kwargs
342348

343349

344-
def get_entrypoint_server_processes(serverproxy_config):
345-
sps = []
350+
def get_entrypoint_server_processes():
351+
processes = []
346352
for entry_point in entry_points(group="jupyter_serverproxy_servers"):
347353
name = entry_point.name
348354
try:
349355
server_process_config = entry_point.load()()
350356
except Exception as e:
351357
warn(f"entry_point {name} was unable to be loaded: {str(e)}")
352358
continue
353-
sps.append(make_server_process(name, server_process_config, serverproxy_config))
354-
return sps
359+
processes.append(ServerProcess(name=name, **server_process_config))
360+
return processes
355361

356362

357363
def make_handlers(base_url: str, server_processes: list[ServerProcess]):
@@ -384,20 +390,36 @@ def _serverproxy_servers_help():
384390

385391
class ServerProxy(Configurable):
386392
servers = Dict(
387-
{},
393+
key_trait=Unicode(),
394+
value_trait=Union([Dict(), Instance(ServerProcess)]),
388395
help="""
389396
Dictionary of processes to supervise & proxy.
390397
391398
Key should be the name of the process. This is also used by default as
392399
the URL prefix, and all requests matching this prefix are routed to this process.
393400
394-
Value should be a dictionary with the following keys:
401+
Value should be an instance of ``ServerProcess`` or a dictionary with the following keys:
395402
396403
"""
397404
+ indent(_serverproxy_servers_help(), " "),
398405
config=True,
399406
)
400407

408+
@validate("servers")
409+
def _validate_servers(self, proposal):
410+
servers = {}
411+
412+
for name, server_process in proposal["value"].items():
413+
if isinstance(server_process, ServerProcess):
414+
server_process.name = server_process.name or name
415+
servers[name] = server_process
416+
else:
417+
kwargs = {"name": name}
418+
kwargs.update(**server_process)
419+
servers[name] = ServerProcess(**kwargs)
420+
421+
return servers
422+
401423
non_service_rewrite_response = Union(
402424
default_value=tuple(),
403425
trait_types=[List(), Tuple(), Callable()],

0 commit comments

Comments
 (0)