From 4f5cc4ee28601a09efc985d7e30f9b9706220353 Mon Sep 17 00:00:00 2001 From: Zachary Sailer Date: Fri, 6 May 2022 16:03:50 -0700 Subject: [PATCH] Backport PR #834: Enable GatewayClient managers to be configurable --- jupyter_server/serverapp.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/jupyter_server/serverapp.py b/jupyter_server/serverapp.py index 37e08d9850..2283acaf33 100644 --- a/jupyter_server/serverapp.py +++ b/jupyter_server/serverapp.py @@ -1451,18 +1451,28 @@ def _observe_contents_manager_class(self, change): ) kernel_manager_class = Type( - default_value=AsyncMappingKernelManager, klass=MappingKernelManager, config=True, help=_i18n("The kernel manager class to use."), ) + @default("kernel_manager_class") + def _default_kernel_manager_class(self): + if self.gateway_config.gateway_enabled: + return "jupyter_server.gateway.managers.GatewayMappingKernelManager" + return AsyncMappingKernelManager + session_manager_class = Type( - default_value=SessionManager, config=True, help=_i18n("The session manager class to use."), ) + @default("session_manager_class") + def _default_session_manager_class(self): + if self.gateway_config.gateway_enabled: + return "jupyter_server.gateway.managers.GatewaySessionManager" + return SessionManager + config_manager_class = Type( default_value=ConfigManager, config=True, @@ -1472,7 +1482,6 @@ def _observe_contents_manager_class(self, change): kernel_spec_manager = Instance(KernelSpecManager, allow_none=True) kernel_spec_manager_class = Type( - default_value=KernelSpecManager, config=True, help=""" The kernel spec manager class to use. Should be a subclass @@ -1483,6 +1492,12 @@ def _observe_contents_manager_class(self, change): """, ) + @default("kernel_spec_manager_class") + def _default_kernel_spec_manager_class(self): + if self.gateway_config.gateway_enabled: + return "jupyter_server.gateway.managers.GatewayKernelSpecManager" + return KernelSpecManager + login_handler_class = Type( default_value=LoginHandler, klass=web.RequestHandler, @@ -1822,15 +1837,6 @@ def init_configurables(self): # this determination, instantiate the GatewayClient config singleton. self.gateway_config = GatewayClient.instance(parent=self) - if self.gateway_config.gateway_enabled: - self.kernel_manager_class = ( - "jupyter_server.gateway.managers.GatewayMappingKernelManager" - ) - self.session_manager_class = "jupyter_server.gateway.managers.GatewaySessionManager" - self.kernel_spec_manager_class = ( - "jupyter_server.gateway.managers.GatewayKernelSpecManager" - ) - self.kernel_spec_manager = self.kernel_spec_manager_class( parent=self, )