[Bug 273666] devel/py-invoke: Change default shell to /bin/sh, Add SUDO option

From: <bugzilla-noreply_at_freebsd.org>
Date: Sun, 10 Sep 2023 01:16:10 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=273666

            Bug ID: 273666
           Summary: devel/py-invoke: Change default shell to /bin/sh, Add
                    SUDO option
           Product: Ports & Packages
           Version: Latest
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: Individual Port(s)
          Assignee: sunpoet@FreeBSD.org
          Reporter: DtxdF@disroot.org
             Flags: maintainer-feedback?(sunpoet@FreeBSD.org)
          Assignee: sunpoet@FreeBSD.org
 Attachment #244741 maintainer-approval+
             Flags:

Created attachment 244741
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=244741&action=edit
py-invoke.patch

Description:

pyinvoke has some issues with the default shell [1], which is /bin/bash. Many
unix-like systems don't have that shell but have /bin/sh. FreeBSD is one of
them, so I think it is worth patching this port to use /bin/sh to avoid the
error in Exception #1.

I have added the SUDO option because it might be useful for those who use sudo
and it also solves the problem described in Exception #2.

[1] https://github.com/pyinvoke/invoke/issues?q=%2Fbin%2Fsh

Exception #1:

```
# python3.9
Python 3.9.17 (main, Aug  6 2023, 01:11:50)
[Clang 14.0.5 (https://github.com/llvm/llvm-project.git llvmorg-14.0.5-0-gc1238
on freebsd13
Type "help", "copyright", "credits" or "license" for more information.
>>> import invoke
>>> invoke.run("whoami")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/invoke/__init__.py", line 50, in
run
    return Context().run(command, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/invoke/context.py", line 104, in
run
    return self._run(runner, command, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/invoke/context.py", line 113, in
_run
    return runner.run(command, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/invoke/runners.py", line 395, in
run
    return self._run_body(command, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/invoke/runners.py", line 440, in
_run_body
    self.start(command, self.opts["shell"], self.env)
  File "/usr/local/lib/python3.9/site-packages/invoke/runners.py", line 1337,
in start
    self.process = Popen(
  File "/usr/local/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/local/lib/python3.9/subprocess.py", line 1837, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/bin/bash'
```

Exception #2:

```
# python3.9
Python 3.9.18 (main, Sep  9 2023, 23:31:39)
[Clang 14.0.5 (https://github.com/llvm/llvm-project.git llvmorg-14.0.5-0-gc1238
on freebsd13
Type "help", "copyright", "credits" or "license" for more information.
>>> import invoke
>>> invoke.run("whoami")
root
<Result cmd='whoami' exited=0>
>>> invoke.sudo()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: sudo() missing 1 required positional argument: 'command'
>>> invoke.sudo("whoami")
/bin/sh: sudo: not found
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/invoke/__init__.py", line 70, in
sudo
    return Context().sudo(command, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/invoke/context.py", line 185, in
sudo
    return self._sudo(runner, command, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/invoke/context.py", line 232, in
_sudo
    return runner.run(cmd_str, watchers=watchers, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/invoke/runners.py", line 395, in
run
    return self._run_body(command, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/invoke/runners.py", line 451, in
_run_body
    return self.make_promise() if self._asynchronous else self._finish()
  File "/usr/local/lib/python3.9/site-packages/invoke/runners.py", line 518, in
_finish
    raise UnexpectedExit(result)
invoke.exceptions.UnexpectedExit: Encountered a bad command exit code!

Command: "sudo -S -p '[sudo] password: ' whoami"

Exit code: 127

Stdout: already printed

Stderr: already printed


```

QA:

* portlint: OK (looks fine.)
* testport: OK (poudriere: 13.2-RELEASE, amd64, SUDO tested)

-- 
You are receiving this mail because:
You are the assignee for the bug.