Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default run.shell to /bin/sh #957

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions invoke/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,16 +440,16 @@ def global_defaults() -> Dict[str, Any]:

.. versionadded:: 1.0
"""
# On Windows, which won't have /bin/bash, check for a set COMSPEC env
# On Windows, which won't have /bin/sh, check for a set COMSPEC env
# var (https://en.wikipedia.org/wiki/COMSPEC) or fallback to an
# unqualified cmd.exe otherwise.
if WINDOWS:
shell = os.environ.get("COMSPEC", "cmd.exe")
# Else, assume Unix, most distros of which have /bin/bash available.
# TODO: consider an automatic fallback to /bin/sh for systems lacking
# /bin/bash; however users may configure run.shell quite easily, so...
# Else, assume a POSIX compatible Unix, where /bin/sh is mandated by
# the standard. Users on more exotic platforms are expected to configure
# run.shell manually.
else:
shell = "/bin/bash"
shell = "/bin/sh"

return {
# TODO: we document 'debug' but it's not truly implemented outside
Expand Down
2 changes: 1 addition & 1 deletion invoke/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def run(self, command: str, **kwargs: Any) -> Optional["Result"]:
Default: ``False``.

:param str shell:
Which shell binary to use. Default: ``/bin/bash`` (on Unix;
Which shell binary to use. Default: ``/bin/sh`` (on Unix;
``COMSPEC`` or ``cmd.exe`` on Windows.)

:param timeout:
Expand Down
2 changes: 1 addition & 1 deletion tests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def basic_settings(self):
"out_stream": None,
"pty": False,
"replace_env": False,
"shell": "/bin/bash",
"shell": "/bin/sh",
"warn": False,
"watchers": [],
},
Expand Down
10 changes: 5 additions & 5 deletions tests/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def _expect_platform_shell(shell):
if WINDOWS:
assert shell.endswith("cmd.exe")
else:
assert shell == "/bin/bash"
assert shell == "/bin/sh"


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

class shell:
def defaults_to_bash_or_cmdexe_when_pty_True(self):
def defaults_to_sh_or_cmdexe_when_pty_True(self):
_expect_platform_shell(self._run(_, pty=True).shell)

def defaults_to_bash_or_cmdexe_when_pty_False(self):
def defaults_to_sh_or_cmdexe_when_pty_False(self):
_expect_platform_shell(self._run(_, pty=False).shell)

def may_be_overridden(self):
Expand Down Expand Up @@ -1651,14 +1651,14 @@ def overridden_fallback_affects_result_pty_value(self):

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

@mock_subprocess(insert_Popen=True)
def defaults_to_bash_or_cmdexe_when_pty_False(self, mock_Popen):
def defaults_to_sh_or_cmdexe_when_pty_False(self, mock_Popen):
self._run(_, pty=False)
_expect_platform_shell(
mock_Popen.call_args_list[0][1]["executable"]
Expand Down