Repository navigation
poetry.bash-completion has multiple syntax errors #4572
Description
-
I am on the latest Poetry version.
-
I have searched the issues of this repo and believe that this is not a duplicate.
-
If an exception occurs when executing a command, I executed it again in debug mode (
-vvvoption). -
OS version and name: macOS 10.14.6 Mojave
-
Poetry version: Poetry (version 1.2.0a2)
-
Link of a Gist with the contents of your pyproject.toml file: N/A
Issue
Generated a completion file for bash via poetry completions bash > /usr/local/etc/profile.d/poetry.bash-completion due to poetry completions bash > /etc/bash_completion.d/poetry.bash-completion not having the /etc/bash_completion.d directory on Mac. Sourced in .bashrc and wound up with a bunch of syntax errors that I had to comment out (i.e., not use.)
.bashrc
. /usr/local/etc/profile.d/poetry.bash-completion
/usr/local/etc/profile.d/poetry.bash-completion
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 40: syntax error near unexpected token `clear'
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 40: ` (cache clear)'
$ which poetry
/usr/local/bin/poetry
$ source ~/.bashrc
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 44: syntax error near unexpected token `list'
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 44: ` (cache list)'
$ source ~/.bashrc
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 56: syntax error near unexpected token `info'
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 56: ` (debug info)'
$ source ~/.bashrc
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 60: syntax error near unexpected token `resolve'
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 60: ` (debug resolve)'
$ source ~/.bashrc
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 64: syntax error near unexpected token `info'
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 64: ` (env info)'
$ source ~/.bashrc
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 68: syntax error near unexpected token `list'
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 68: ` (env list)'
$ source ~/.bashrc
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 72: syntax error near unexpected token `remove'
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 72: ` (env remove)'
$ source ~/.bashrc
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 76: syntax error near unexpected token `use'
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 76: ` (env use)'
$ source ~/.bashrc
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 108: syntax error near unexpected token `add'
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 108: ` (plugin add)'
$ source ~/.bashrc
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 112: syntax error near unexpected token `remove'
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 112: ` (plugin remove)'
$ !!
source ~/.bashrc
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 116: syntax error near unexpected token `show'
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 116: ` (plugin show)'
$ !!
source ~/.bashrc
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 136: syntax error near unexpected token `update'
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 136: ` (self update)'
$
$ !!
source ~/.bashrc
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 148: syntax error near unexpected token `add'
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 148: ` (source add)'
$ !!
source ~/.bashrc
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 152: syntax error near unexpected token `remove'
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 152: ` (source remove)'
$ !!
source ~/.bashrc
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 156: syntax error near unexpected token `show'
-bash: /usr/local/etc/profile.d/poetry.bash-completion: line 156: ` (source show)'
$ !!
source ~/.bashrc
$
Activity
pythoninthegrass commentedon Sep 29, 2021
Attached the generated completion file with commented out lines.
sgaist commentedon Oct 3, 2021
Hi,
Can you add the version of bash you are using and how you installed Poetry and bash ?
I have tested your file with bash 5.1.8 on High Sierra and it worked properly.
pythoninthegrass commentedon Oct 4, 2021
bashwas installed viabrewandpoetryispip.pythoninthegrass commentedon Oct 4, 2021
Updated bash to 5.1.8(1)-release. Re-ran the completion command and get this:
sgaist commentedon Oct 5, 2021
Did you check the value of
$BASH_VERSION?IIRC, it's used by bash completion to load its helper functions and if it's too old it won't but without a warning.
An mismatched value can happen for the following reason: your login shell is still configured to point on the macOS provided bash and your "Shell opens with" Terminal setting is set to "Default login shell".
You have two options here:
For number 2, you need to add your brew bash path to the list of available shells in
/etc/shells(requires root access) and then usechsh -s <path/to/bash>as your current user.pythoninthegrass commentedon Oct 5, 2021
Good catch with
$BASH_VERSION. It was pointing to the old v3.x version of bash while the shell itself was up-to-date and the$PATHcalled the right one when checking the version 🤔Set both the absolute path in iTerm (login shell to custom shell) to the brew
bashand appending the same to/etc/shells, I'm now getting:Re-ran
poetry completions bash > /usr/local/etc/profile.d/poetry.bash-completion, but no joy:sgaist commentedon Oct 6, 2021
From the looks of it, you did not install the
bash-completionpackage.Do that first and then put the poetry completion file under
/usr/local/etc/bash_completion.d/.pythoninthegrass commentedon Oct 6, 2021
This is what I've been doing:
Which appears to be supported according to
poetry help completions.ablacklama commentedon Oct 30, 2021
I'm getting the same issue here on Ubuntu using the exact same commands and when i try to run it as a bash script normally. I have updated my bash and bash-completions to no avail.
The problem seems to be that completions for subcommands are written like
(command subcommand) opts="${opts} ..." ;;which isn't valid bash as far as i can tell. Separating the command and subcommand with a space doesn't seem to work.
But i'm no expert so take that with a grain of salt.
This only is a problem with
1.2.0a2and doesn't exist in1.1.0abn commentedon Oct 30, 2021
I suspect this is an issue with
cleoas we use it to handle the CLI ux, the issue seems to be how subcommands are being handled.abn commentedon May 11, 2022
This one still fails accross all platforms.
4 remaining items
raffraffraff commentedon Oct 28, 2022
The poetry maintainers are playing whack-a-mole with duplicate tickets. Poetry users will probably keep creating more issues for this bug as long as the bug still exists in the latest version of poetry, and an open issue for the bug doesn't exist. Hand-waving at an upstream repo and closing all of the issues makes it extremely difficult to follow what's going on.
Suggestion: leave 1 issue open for this bug in poetry and link it to the root cause issue in cleo.
Edit: This issue might be a good one to use, since it's linked to the cleo PR
neersighted commentedon Oct 28, 2022
I personally haven't looked at this issue for a minute (it merely lives in my 'common duplicates' doc) -- looks like it was closed by mistake as the Cleo PR should have specified Relates-To or similar. This shouldn't be closed in Poetry until after the Cleo release and subsequent bump of our constraint.
raffraffraff commentedon Oct 30, 2022
If anyone wants working bash completion for poetry now, I created a gist: https://gist.github.com/raffraffraff/36b7a8cd1a4308150d7f843724a19ff9
I wanted an excuse to learn the poetry syntax, plus having decent shell completion makes learning it much easier.
YMMV, but it's working great for me. It's able to complete commands, positional args and options, and even suggests package names, source names, config options and caches where appropriate (and I don't think the official shell completion will do that).
koutoftimer commentedon Oct 30, 2022
@raffraffraff without pull request it will be lost in the internet for sure. (I have fixed completions with vim+macros in <1 min).
raffraffraff commentedon Oct 30, 2022
@koutoftimer I didn't send a pull request because poetry uses cleo for bash completions, but my script is 'hand made'. I'm just sharing here in case it's useful to others.
neersighted commentedon Nov 11, 2022
This is well-known and universal; please refrain from "me too" as it only adds noise and distracts the people trying to get Cleo 1.0 over the finish line so we can ship the (already merged) fix 😄
Secrus commentedon Nov 22, 2022
Completion bugs are now fixed with the incoming release.
ab commentedon Dec 6, 2022
When is version 1.3.0 expected to be published?
neersighted commentedon Dec 6, 2022
When it's ready/the maintainers have had time to finalize the changelog (including any late merges).
benkehoe commentedon Dec 6, 2022
If you go to the "watch" dropdown for this repository in the upper right corner of the page and click "custom", you can select to be notified of releases, which should send you an alert when 1.3.0 is published.
pythoninthegrass commentedon Jan 26, 2023
Just wanted to close the loop here (know the issue is closed haha) — running bash 5.2.15 and poetry 1.3.2 appears to have resolved the completion errors after re-exporting the completion script via
poetry completions bash > /usr/local/etc/profile.d/poetry.bash-completionAppreciate everyone's help 🙏
github-actions commentedon Feb 29, 2024
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.