poetry: poetry.bash-completion has multiple syntax errors

  • 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 (-vvv option).

  • 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
$

Full poetry.bash-completion

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 9
  • Comments: 25 (6 by maintainers)

Most upvoted comments

This one still fails accross all platforms.

$ poetry --version
Poetry (version 1.2.0b2dev0)
$ echo $BASH_VERSION
5.1.16(1)-release
$ poetry completions bash | bash
bash: line 40: syntax error near unexpected token `clear'
bash: line 40: `            (cache clear)'

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.

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).

Updated bash to 5.1.8(1)-release. Re-ran the completion command and get this:

$ source ~/.bashrc
-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)'

Completion bugs are now fixed with the incoming release.

Can we reopen this issue as it is still a problem and the PR that was supposed to close it, did actually do it (see there)?

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.0a2 and doesn’t exist in 1.1.0

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

This is what I’ve been doing:

$ poetry completions bash > /usr/local/etc/profile.d/poetry.bash-completion
$ ll /usr/local/etc/profile.d/poetry.bash-completion
-rw-r--r--  1 lance.stephens  admin   4.4K Oct  6 12:56 /usr/local/etc/profile.d/poetry.bash-completion
$ grep 'poetry.bash-completion' ~/.bashrc
. /usr/local/etc/profile.d/poetry.bash-completion
$ source ~/.bashrc
-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 appears to be supported according to poetry help completions.

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 😄

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.

@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.