Bug 273666 - devel/py-invoke: Change default shell to /bin/sh, Add SUDO option
Summary: devel/py-invoke: Change default shell to /bin/sh, Add SUDO option
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Po-Chuan Hsieh
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-09-10 01:16 UTC by Jesús Daniel Colmenares Oviedo
Modified: 2023-09-30 01:10 UTC (History)
0 users

See Also:
bugzilla: maintainer-feedback? (sunpoet)


Attachments
py-invoke.patch (2.33 KB, patch)
2023-09-10 01:16 UTC, Jesús Daniel Colmenares Oviedo
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jesús Daniel Colmenares Oviedo 2023-09-10 01:16:10 UTC
Created attachment 244741 [details]
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)
Comment 1 Jesús Daniel Colmenares Oviedo 2023-09-10 19:43:57 UTC
Excuse me, I set maintainer-approval to + when I shouldn't have.
Comment 2 commit-hook freebsd_committer freebsd_triage 2023-09-30 00:57:53 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=aebb0cb4a8273d786504dc28027200ebd71a42ac

commit aebb0cb4a8273d786504dc28027200ebd71a42ac
Author:     Po-Chuan Hsieh <sunpoet@FreeBSD.org>
AuthorDate: 2023-09-30 00:33:29 +0000
Commit:     Po-Chuan Hsieh <sunpoet@FreeBSD.org>
CommitDate: 2023-09-30 00:46:34 +0000

    devel/py-invoke: Change default shell from bash to sh

    - Add SUDO option
    - Bump PORTREVISION for package change

    PR:             273666
    Reported by:    Jesus Daniel Colmenares Oviedo <DtxdF@disroot.org>

 devel/py-invoke/Makefile               |  6 ++++
 devel/py-invoke/files/patch-bash (new) | 55 ++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)
Comment 3 Po-Chuan Hsieh freebsd_committer freebsd_triage 2023-09-30 01:10:34 UTC
Committed. Thanks!