From 05310a18e9172484a42da4a6e584d9fbc229f99c Mon Sep 17 00:00:00 2001 From: Wh1isper <9573586@qq.com> Date: Wed, 10 Jan 2024 10:14:23 +0800 Subject: [PATCH 1/3] Set terminals_available False when not enabled --- jupyter_server_terminals/app.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/jupyter_server_terminals/app.py b/jupyter_server_terminals/app.py index 8ccbc4f..ae3c5cc 100644 --- a/jupyter_server_terminals/app.py +++ b/jupyter_server_terminals/app.py @@ -37,6 +37,7 @@ class TerminalsExtensionApp(ExtensionApp): def initialize_settings(self) -> None: """Initialize settings.""" if not self.serverapp or not self.serverapp.terminals_enabled: + self.settings.update({"terminals_available": False}) return self.initialize_configurables() self.settings.update( @@ -75,6 +76,11 @@ def initialize_handlers(self) -> None: """Initialize handlers.""" if not self.serverapp or not self.serverapp.terminals_enabled: # Checking self.terminals_available instead breaks enabling terminals + + # webapp settings for backwards compat (used by nbclassic), #12 + self.serverapp.web_app.settings["terminals_available"] = self.settings[ + "terminals_available" + ] return self.handlers.append( ( From c4bf03b0787af4e751c6d3340eb11fb87dc4c2d1 Mon Sep 17 00:00:00 2001 From: Wh1isper <9573586@qq.com> Date: Wed, 10 Jan 2024 10:32:29 +0800 Subject: [PATCH 2/3] Add some testing on fields --- jupyter_server_terminals/app.py | 4 +++- tests/test_disable_app.py | 13 +++++++++++++ tests/test_terminal.py | 6 ++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/test_disable_app.py diff --git a/jupyter_server_terminals/app.py b/jupyter_server_terminals/app.py index ae3c5cc..7147a7e 100644 --- a/jupyter_server_terminals/app.py +++ b/jupyter_server_terminals/app.py @@ -74,9 +74,11 @@ def initialize_configurables(self) -> None: def initialize_handlers(self) -> None: """Initialize handlers.""" - if not self.serverapp or not self.serverapp.terminals_enabled: + if not self.serverapp: # Checking self.terminals_available instead breaks enabling terminals + return + if not self.serverapp.terminals_enabled: # webapp settings for backwards compat (used by nbclassic), #12 self.serverapp.web_app.settings["terminals_available"] = self.settings[ "terminals_available" diff --git a/tests/test_disable_app.py b/tests/test_disable_app.py new file mode 100644 index 0000000..6538602 --- /dev/null +++ b/tests/test_disable_app.py @@ -0,0 +1,13 @@ +import pytest +from traitlets.config.loader import Config + + +@pytest.fixture() +def jp_server_config(): + return Config({"ServerApp": {"terminals_enabled": False}}) + + +async def test_not_enabled(jp_configurable_serverapp): + assert jp_configurable_serverapp().terminals_enabled is False + assert jp_configurable_serverapp().web_app.settings["terminals_available"] is False + assert "terminal_manager" not in jp_configurable_serverapp().web_app.settings diff --git a/tests/test_terminal.py b/tests/test_terminal.py index 6516eb7..ef96907 100644 --- a/tests/test_terminal.py +++ b/tests/test_terminal.py @@ -236,6 +236,12 @@ async def test_terminal_create_with_bad_cwd(jp_fetch, jp_ws_fetch): assert non_existing_path not in message_stdout +async def test_app_config(jp_configurable_serverapp): + assert jp_configurable_serverapp().terminals_enabled is True + assert jp_configurable_serverapp().web_app.settings["terminals_available"] is True + assert jp_configurable_serverapp().web_app.settings["terminal_manager"] + + async def test_culling_config(jp_configurable_serverapp): terminal_mgr_config = jp_configurable_serverapp().config.ServerApp.TerminalManager assert terminal_mgr_config.cull_inactive_timeout == CULL_TIMEOUT From d3f94dc2e7a95d51c1b2d1f339065485cf763472 Mon Sep 17 00:00:00 2001 From: Wh1isper <9573586@qq.com> Date: Sat, 13 Jan 2024 07:36:39 +0800 Subject: [PATCH 3/3] Update comments --- jupyter_server_terminals/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyter_server_terminals/app.py b/jupyter_server_terminals/app.py index 7147a7e..e10a5b4 100644 --- a/jupyter_server_terminals/app.py +++ b/jupyter_server_terminals/app.py @@ -75,7 +75,7 @@ def initialize_configurables(self) -> None: def initialize_handlers(self) -> None: """Initialize handlers.""" if not self.serverapp: - # Checking self.terminals_available instead breaks enabling terminals + # Already set `terminals_available` as `False` in `initialize_settings` return if not self.serverapp.terminals_enabled: