Skip to content

Commit be7cb49

Browse files
committed
only configure the classes if they haven't been previously configured
1 parent 01217ca commit be7cb49

File tree

1 file changed

+35
-28
lines changed
  • jupyter_server_documents

1 file changed

+35
-28
lines changed

jupyter_server_documents/app.py

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -95,35 +95,42 @@ def get_fileid_manager():
9595
)
9696

9797
def _link_jupyter_server_extension(self, server_app):
98-
"""Setup custom config needed by this extension."""
98+
"""Setup custom config needed by this extension.
99+
100+
Only applies configuration if not already set by user config.
101+
"""
99102
c = Config()
100-
# Use nextgen-kernels-api's multi-kernel manager
101-
# This manager disables activity watching and buffering (which we don't need)
102-
c.ServerApp.kernel_manager_class = "nextgen_kernels_api.services.kernels.kernelmanager.MultiKernelManager"
103-
c.ServerApp.kernel_websocket_connection_class = 'nextgen_kernels_api.services.kernels.connection.kernel_client_connection.KernelClientWebsocketConnection'
104-
105-
# Configure MultiKernelManager to use nextgen's KernelManager
106-
c.MultiKernelManager.kernel_manager_class = "nextgen_kernels_api.services.kernels.kernelmanager.KernelManager"
107-
108-
# Configure the KernelManager to use DocumentAwareKernelClient
109-
c.KernelManager.client_class = "jupyter_server_documents.kernel_client.DocumentAwareKernelClient"
110-
c.KernelManager.client_factory = "jupyter_server_documents.kernel_client.DocumentAwareKernelClient"
111-
112-
# Use custom session manager for YRoom integration
113-
c.ServerApp.session_manager_class = "jupyter_server_documents.session_manager.YDocSessionManager"
114-
115-
# Configure websocket connection to exclude output messages
116-
# Output messages are handled by DocumentAwareKernelClient's output processor
117-
# and should not be sent to websocket clients to avoid duplicate processing
118-
c.KernelClientWebsocketConnection.exclude_msg_types = [
119-
("status", "iopub"),
120-
("stream", "iopub"),
121-
("display_data", "iopub"),
122-
("execute_result", "iopub"),
123-
("error", "iopub"),
124-
("update_display_data", "iopub"),
125-
("clear_output", "iopub")
126-
]
103+
104+
# Only configure if not already set in user config
105+
if not server_app.config.ServerApp.get("kernel_manager_class"):
106+
c.ServerApp.kernel_manager_class = "nextgen_kernels_api.services.kernels.kernelmanager.MultiKernelManager"
107+
108+
if not server_app.config.ServerApp.get("kernel_websocket_connection_class"):
109+
c.ServerApp.kernel_websocket_connection_class = "nextgen_kernels_api.services.kernels.connection.kernel_client_connection.KernelClientWebsocketConnection"
110+
111+
if not server_app.config.ServerApp.get("session_manager_class"):
112+
c.ServerApp.session_manager_class = "jupyter_server_documents.session_manager.YDocSessionManager"
113+
114+
# Configure kernel manager hierarchy
115+
if not server_app.config.MultiKernelManager.get("kernel_manager_class"):
116+
c.MultiKernelManager.kernel_manager_class = "nextgen_kernels_api.services.kernels.kernelmanager.KernelManager"
117+
118+
# Configure kernel client
119+
if not server_app.config.KernelManager.get("client_class"):
120+
c.KernelManager.client_class = "jupyter_server_documents.kernel_client.DocumentAwareKernelClient"
121+
c.KernelManager.client_factory = "jupyter_server_documents.kernel_client.DocumentAwareKernelClient"
122+
123+
# Configure websocket message filtering
124+
if not server_app.config.KernelClientWebsocketConnection.get("exclude_msg_types"):
125+
c.KernelClientWebsocketConnection.exclude_msg_types = [
126+
("status", "iopub"),
127+
("stream", "iopub"),
128+
("display_data", "iopub"),
129+
("execute_result", "iopub"),
130+
("error", "iopub"),
131+
("update_display_data", "iopub"),
132+
("clear_output", "iopub"),
133+
]
127134

128135
server_app.update_config(c)
129136
super()._link_jupyter_server_extension(server_app)

0 commit comments

Comments
 (0)