-
Notifications
You must be signed in to change notification settings - Fork 349
Open
Labels
Description
Problem
We need a way to set the terminal prompt (e.g. with PS1
environment variable) for reproducible snapshots as in jupyterlab/jupyterlab#17656. This may be also desirable for real deployments. While terminado classes accept both shell_command
and extra_env
, the latter is not currently supported in jupyter-server traitlet definition:
jupyter_server/jupyter_server/serverapp.py
Lines 1491 to 1495 in 04dd3e7
terminado_settings = Dict( | |
Union([List(), Unicode()]), | |
config=True, | |
help=_i18n('Supply overrides for terminado. Currently only supports "shell_command".'), | |
) |
Proposed Solution
Use per-key traitlets to accept shell_command
as an union of string/list and extra_env
as a dict with string keys.
Additional context
Need to add a test around here:
jupyter_server/tests/test_terminal.py
Lines 278 to 297 in 04dd3e7
@pytest.mark.parametrize( | |
"terminado_settings,expected_shell,min_traitlets", | |
[ | |
("shell_command=\"['/path/to/shell', '-l']\"", ["/path/to/shell", "-l"], "5.4"), | |
('shell_command="/string/path/to/shell -l"', ["/string/path/to/shell", "-l"], "5.1"), | |
], | |
) | |
def test_shell_command_override( | |
terminado_settings, expected_shell, min_traitlets, jp_configurable_serverapp | |
): | |
pytest.importorskip("traitlets", minversion=min_traitlets) | |
argv = shlex.split(f"--ServerApp.terminado_settings={terminado_settings}") | |
app = jp_configurable_serverapp(argv=argv) | |
if os.name == "nt": | |
assert app.web_app.settings["terminal_manager"].shell_command in ( | |
expected_shell, | |
" ".join(expected_shell), | |
) | |
else: | |
assert app.web_app.settings["terminal_manager"].shell_command == expected_shell |