Community Packages

Please read this before reporting a bug:
https://wiki.archlinux.org/title/Bug_reporting_guidelines

Do NOT report bugs when a package is just outdated, or it is in the AUR. Use the 'flag out of date' link on the package page, or the Mailing List.

REPEAT: Do NOT report bugs for outdated packages!
Tasklist

FS#76996 - [python-poetry] shell completion scripts are empty

Attached to Project: Community Packages
Opened by David Joaquín Shourabi Porcel (djsp) - Tuesday, 03 January 2023, 19:34 GMT
Last edited by Caleb Maclennan (alerque) - Friday, 06 January 2023, 12:54 GMT
Task Type Bug Report
Category Packages
Status Closed
Assigned To Caleb Maclennan (alerque)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

The shell completion scripts included in the [package `python-poetry`](https://archlinux.org/packages/community/any/python-poetry/) are empty:

```
$ wc --bytes -- /usr/share/bash-completion/completions/poetry /usr/share/fish/vendor_completions.d/poetry.fish /usr/share/zsh/site-functions/_poetry
0 /usr/share/bash-completion/completions/poetry
0 /usr/share/fish/vendor_completions.d/poetry.fish
0 /usr/share/zsh/site-functions/_poetry
0 total
```

The [`PKGBUILD`](https://github.com/archlinux/svntogit-community/blob/packages/python-poetry/trunk/PKGBUILD) invokes a [Python script](https://github.com/archlinux/svntogit-community/blob/packages/python-poetry/trunk/poetry-completions-generator) to generate them:

```
./poetry-completions-generator completions bash |
sed "#$srcdir#d" |
install -Dm644 /dev/stdin "$pkgdir/usr/share/bash-completion/completions/poetry"
./poetry-completions-generator completions zsh |
sed "#$srcdir#d" |
install -Dm644 /dev/stdin "$pkgdir/usr/share/zsh/site-functions/_poetry"
./poetry-completions-generator completions fish |
install -Dm644 /dev/stdin "$pkgdir/usr/share/fish/vendor_completions.d/poetry.fish"
```

```
import sys
from poetry.console import main

sys.argv = ['poetry', 'completions', sys.argv.pop()]

main()
```

The Python script fails because the function `main` is no longer in the module `poetry.console`:

```
$ python
Python 3.10.9 (main, Dec 19 2022, 17:35:49) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> from poetry.console import main
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'main' from 'poetry.console' (/usr/lib/python3.10/site-packages/poetry/console/__init__.py)
>>> quit()
```

The function `main` was moved with [upstream git commit `a8d02ef59f60c001458f27b7cb2557a346cfb6b6`](https://github.com/python-poetry/poetry/commit/a8d02ef59f60c001458f27b7cb2557a346cfb6b6#diff-40d2f9aa8026c63507b86318987a0b426c2d529c3cc3b26ab09871980b44c7cb) in January 2021 to the module `poetry.console.application`. Adjusting the `import` statement solves the issue:

```
$ python -- - bash
Python 3.10.9 (main, Dec 19 2022, 17:35:49) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> from poetry.console.application import main
>>> sys.argv = ['poetry', 'completions', sys.argv.pop()]
>>> main()
_poetry_d35cb51f6b8ed5a1_complete()
{
local cur script coms opts com
COMPREPLY=()
_get_comp_words_by_ref -n : cur words

...
```

To incorporate this fix, apply the patch `1-fix-shell-completion-script-generation.patch` attached to this bug report.

Building the package succeeds despite the Python script's failure because Bash is ignoring the Python script's exit status:

> The exit status of a pipeline is the exit status of the last command in the pipeline, unless the `pipefail` option is enabled (see [The Set Builtin](https://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin)).
> If `pipefail` is enabled, the pipeline’s return status is the value of the last (rightmost) command to exit with a non-zero status, or zero if all commands exit successfully.

To make the package build process fail and prevent this issue if/when upstream changes the location (or name, or semantics,…) of the function `main` again, we can enable the shell option `pipefail` in the relevant section of the `PKGBUILD`. To do so, apply the patch `2-fail-if-shell-completion-script-generation-fails.patch` attached to this bug report.
This task depends upon

Closed by  Caleb Maclennan (alerque)
Friday, 06 January 2023, 12:54 GMT
Reason for closing:  Fixed
Additional comments about closing:  Thanks for the detailed report and patches! I've applied them in python-poetry-1.3.1-3.

Loading...