Skip to content

Commit 66962b5

Browse files
dlukeskevin-bates
andcommitted
Improve login shell heuristics
Co-authored-by: Kevin Bates <[email protected]>
1 parent 9e18c8e commit 66962b5

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

jupyter_server/terminal/__init__.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import sys
23

34
import terminado
45
from ..utils import check_version
@@ -19,16 +20,18 @@ def initialize(webapp, root_dir, connection_url, settings):
1920
default_shell = 'powershell.exe'
2021
else:
2122
default_shell = which('sh')
22-
shell = settings.get('shell_command',
23+
shell_override = settings.get('shell_command')
24+
shell = (
2325
[os.environ.get('SHELL') or default_shell]
26+
if shell_override is None
27+
else shell_override
2428
)
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():
3235
shell.append('-l')
3336
terminal_manager = webapp.settings['terminal_manager'] = NamedTermManager(
3437
shell_command=shell,

0 commit comments

Comments
 (0)