Skip to content

Commit 967a6d1

Browse files
committed
Default run.shell to /bin/sh
`/bin/bash` is not availabe on some popular distributions, for example NixOS. Defaulting to the more conservative `/bin/sh` improves portability.
1 parent ee9d862 commit 967a6d1

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

invoke/config.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -440,16 +440,16 @@ def global_defaults() -> Dict[str, Any]:
440440
441441
.. versionadded:: 1.0
442442
"""
443-
# On Windows, which won't have /bin/bash, check for a set COMSPEC env
443+
# On Windows, which won't have /bin/sh, check for a set COMSPEC env
444444
# var (https://en.wikipedia.org/wiki/COMSPEC) or fallback to an
445445
# unqualified cmd.exe otherwise.
446446
if WINDOWS:
447447
shell = os.environ.get("COMSPEC", "cmd.exe")
448-
# Else, assume Unix, most distros of which have /bin/bash available.
449-
# TODO: consider an automatic fallback to /bin/sh for systems lacking
450-
# /bin/bash; however users may configure run.shell quite easily, so...
448+
# Else, assume a POSIX compatible Unix, where /bin/sh is mandated by
449+
# the standard. Users on more exotic platforms are expected to configure
450+
# run.shell manually.
451451
else:
452-
shell = "/bin/bash"
452+
shell = "/bin/sh"
453453

454454
return {
455455
# TODO: we document 'debug' but it's not truly implemented outside

invoke/runners.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def run(self, command: str, **kwargs: Any) -> Optional["Result"]:
335335
Default: ``False``.
336336
337337
:param str shell:
338-
Which shell binary to use. Default: ``/bin/bash`` (on Unix;
338+
Which shell binary to use. Default: ``/bin/sh`` (on Unix;
339339
``COMSPEC`` or ``cmd.exe`` on Windows.)
340340
341341
:param timeout:

tests/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def basic_settings(self):
107107
"out_stream": None,
108108
"pty": False,
109109
"replace_env": False,
110-
"shell": "/bin/bash",
110+
"shell": "/bin/sh",
111111
"warn": False,
112112
"watchers": [],
113113
},

tests/runners.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def _expect_platform_shell(shell):
8181
if WINDOWS:
8282
assert shell.endswith("cmd.exe")
8383
else:
84-
assert shell == "/bin/bash"
84+
assert shell == "/bin/sh"
8585

8686

8787
def _make_tcattrs(cc_is_ints=True, echo=False):
@@ -218,10 +218,10 @@ def kwarg_beats_config(self):
218218
assert runner.run(_, pty=True).pty is True
219219

220220
class shell:
221-
def defaults_to_bash_or_cmdexe_when_pty_True(self):
221+
def defaults_to_sh_or_cmdexe_when_pty_True(self):
222222
_expect_platform_shell(self._run(_, pty=True).shell)
223223

224-
def defaults_to_bash_or_cmdexe_when_pty_False(self):
224+
def defaults_to_sh_or_cmdexe_when_pty_False(self):
225225
_expect_platform_shell(self._run(_, pty=False).shell)
226226

227227
def may_be_overridden(self):
@@ -1651,14 +1651,14 @@ def overridden_fallback_affects_result_pty_value(self):
16511651

16521652
class shell:
16531653
@mock_pty(insert_os=True)
1654-
def defaults_to_bash_or_cmdexe_when_pty_True(self, mock_os):
1654+
def defaults_to_sh_or_cmdexe_when_pty_True(self, mock_os):
16551655
# NOTE: yea, windows can't run pty is true, but this is really
16561656
# testing config behavior, so...meh
16571657
self._run(_, pty=True)
16581658
_expect_platform_shell(mock_os.execve.call_args_list[0][0][0])
16591659

16601660
@mock_subprocess(insert_Popen=True)
1661-
def defaults_to_bash_or_cmdexe_when_pty_False(self, mock_Popen):
1661+
def defaults_to_sh_or_cmdexe_when_pty_False(self, mock_Popen):
16621662
self._run(_, pty=False)
16631663
_expect_platform_shell(
16641664
mock_Popen.call_args_list[0][1]["executable"]

0 commit comments

Comments
 (0)