1
1
import os
2
+ import sys
2
3
3
4
import terminado
4
5
from ..utils import check_version
@@ -19,16 +20,18 @@ def initialize(webapp, root_dir, connection_url, settings):
19
20
default_shell = 'powershell.exe'
20
21
else :
21
22
default_shell = which ('sh' )
22
- shell = settings .get ('shell_command' ,
23
+ shell_override = settings .get ('shell_command' )
24
+ shell = (
23
25
[os .environ .get ('SHELL' ) or default_shell ]
26
+ if shell_override is None
27
+ else shell_override
24
28
)
25
- # Enable login mode - to automatically source the /etc/profile
26
- # script, but only for non-nested shells; for nested shells, it's
27
- # superfluous and may even be harmful (e.g. on macOS, where login
28
- # shells invoke /usr/libexec/path_helper to add entries from
29
- # /etc/paths{,.d} to the PATH, reordering it in the process and
30
- # potentially overriding virtualenvs and other PATH modifications)
31
- if os .name != 'nt' and int (os .environ .get ("SHLVL" , 0 )) < 1 :
29
+ # When the notebook server is not running in a terminal (e.g. when
30
+ # it's launched by a JupyterHub spawner), it's likely that the user
31
+ # environment hasn't been fully set up. In that case, run a login
32
+ # shell to automatically source /etc/profile and the like, unless
33
+ # the user has specifically set a preferred shell command.
34
+ if os .name != 'nt' and shell_override is None and not sys .stdout .isatty ():
32
35
shell .append ('-l' )
33
36
terminal_manager = webapp .settings ['terminal_manager' ] = NamedTermManager (
34
37
shell_command = shell ,
0 commit comments