Skip to content

Allow to pass extra_env down to terminado to set PS1 variable in terminals #1537

Open
@krassowski

Description

@krassowski

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:

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:

@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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions