From 6b2a7b212ede40adb55df33c45ebde0e4aa94e1e Mon Sep 17 00:00:00 2001 From: Rishab87 Date: Fri, 18 Jul 2025 18:49:28 +0530 Subject: [PATCH] added per-key traitlets and test for extra_env --- jupyter_server/serverapp.py | 12 ++++++++++-- tests/test_terminal.py | 11 +++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/jupyter_server/serverapp.py b/jupyter_server/serverapp.py index 1c70dd60ab..52141898e6 100644 --- a/jupyter_server/serverapp.py +++ b/jupyter_server/serverapp.py @@ -1488,10 +1488,18 @@ def _default_allow_remote(self) -> bool: """ ), ) + terminado_settings = Dict( - Union([List(), Unicode()]), + per_key_traits={ + "shell_command": Union( + [List(), Unicode()], help="The shell command to execute in the terminal." + ), + "extra_env": Dict( + Unicode(), help="Extra environment variables to set in the terminal." + ), + }, config=True, - help=_i18n('Supply overrides for terminado. Currently only supports "shell_command".'), + help=_i18n("Supply overrides for terminado."), ) cookie_options = Dict( diff --git a/tests/test_terminal.py b/tests/test_terminal.py index 8f35c7df60..6614098482 100644 --- a/tests/test_terminal.py +++ b/tests/test_terminal.py @@ -297,6 +297,17 @@ def test_shell_command_override( assert app.web_app.settings["terminal_manager"].shell_command == expected_shell +def test_terminal_extra_env_override(jp_configurable_serverapp): + config = Config({"ServerApp": {"terminado_settings": {"extra_env": {"PS1": "jupyter> "}}}}) + + app = jp_configurable_serverapp(config=config) + terminado_settings = getattr(app, "terminado_settings", {}) + + assert "extra_env" in terminado_settings + assert "PS1" in terminado_settings["extra_env"] + assert terminado_settings["extra_env"]["PS1"] == "jupyter> " + + def test_importing_shims(): with warnings.catch_warnings(): warnings.simplefilter("ignore")