jupyter / terminado

Terminals served by tornado websockets
http://terminado.readthedocs.org/en/latest/
BSD 2-Clause "Simplified" License
368 stars 95 forks source link

custom environment variables per terminal #164

Closed antoine-galataud closed 2 years ago

antoine-galataud commented 2 years ago

I have a use case where I'd like to pass extra environment variables to a new terminal. I would instantiate it using something like:

curl -XPOST'http://localhost:8888/api/terminals' \
     -d '{"extra_env": {"VAR1": "value1", "VAR2": "value2"}}'

and this would propagate env vars to the created terminal.

I guess it could be done the same way than for extra_env dict that is a class field of TermManagerBase (hence can't be used in my specific case).

For instance here: https://github.com/jupyter/terminado/blob/ad8b9bbfd559c3b56b0708ce2c22666fdf0b5ca6/terminado/management.py#L189-L190 could be followed by

term_env = kwargs.get("extra_env", {})
if term_env and isinstance(term_env, dict):
  _update_removing(env, term_env)

(making terminal env supersede manager-scoped env)

blink1073 commented 2 years ago

Makes sense to me, happy to accept a PR!