Skip to content

poetry.bash-completion has multiple syntax errors #4572

Closed
python-poetry/cleo
#247

Description

@pythoninthegrass
  • 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

Activity

  1. pythoninthegrass commented on Sep 29, 2021

    @pythoninthegrass
    Author

    Attached the generated completion file with commented out lines.

  2. sgaist commented on Oct 3, 2021

    @sgaist

    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.

  3. pythoninthegrass commented on Oct 4, 2021

    @pythoninthegrass
    Author

    bash was installed via brew and poetry is pip.

    $ bash --version
    GNU bash, version 5.0.11(1)-release (x86_64-apple-darwin18.6.0)
    Copyright (C) 2019 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    
    This is free software; you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
     $ pip list
    Package            Version
    ------------------ ---------
    ...
    poetry             1.2.0a2
    poetry-core        1.1.0a6
  4. pythoninthegrass commented on Oct 4, 2021

    @pythoninthegrass
    Author

    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)'
  5. sgaist commented on Oct 5, 2021

    @sgaist

    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:

    1. Change "Shell opens with" to point to your brew bash
    2. Change the default shell used when you login keeping the "Shell opens with" default value

    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 use chsh -s <path/to/bash> as your current user.

  6. pythoninthegrass commented on Oct 5, 2021

    @pythoninthegrass
    Author

    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 $PATH called the right one when checking the version 🤔

    Set both the absolute path in iTerm (login shell to custom shell) to the brew bash and appending the same to /etc/shells, I'm now getting:

    $ echo $BASH_VERSION
    5.1.8(1)-release

    Screen Shot 2021-10-05 at 5 32 17 PM

    Re-ran poetry completions bash > /usr/local/etc/profile.d/poetry.bash-completion, but no joy:

    $ 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)'
  7. sgaist commented on Oct 6, 2021

    @sgaist

    From the looks of it, you did not install the bash-completion package.

    Do that first and then put the poetry completion file under /usr/local/etc/bash_completion.d/.

  8. pythoninthegrass commented on Oct 6, 2021

    @pythoninthegrass
    Author

    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.

  9. ablacklama commented on Oct 30, 2021

    @ablacklama

    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

  10. added
    area/cliRelated to the command line
    and removed
    status/triageThis issue needs to be triaged
    on Oct 30, 2021
  11. abn commented on Oct 30, 2021

    @abn
    Member

    I suspect this is an issue with cleo as we use it to handle the CLI ux, the issue seems to be how subcommands are being handled.

  12. abn commented on May 11, 2022

    @abn
    Member

    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)'
  13. 4 remaining items

  14. raffraffraff commented on Oct 28, 2022

    @raffraffraff

    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

  15. neersighted commented on Oct 28, 2022

    @neersighted
    Member

    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.

  16. raffraffraff commented on Oct 30, 2022

    @raffraffraff

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

  17. koutoftimer commented on Oct 30, 2022

    @koutoftimer

    @raffraffraff without pull request it will be lost in the internet for sure. (I have fixed completions with vim+macros in <1 min).

  18. raffraffraff commented on Oct 30, 2022

    @raffraffraff

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

  19. neersighted commented on Nov 11, 2022

    @neersighted
    Member

    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 😄

  20. Secrus commented on Nov 22, 2022

    @Secrus
    Member

    Completion bugs are now fixed with the incoming release.

  21. ab commented on Dec 6, 2022

    @ab

    When is version 1.3.0 expected to be published?

  22. neersighted commented on Dec 6, 2022

    @neersighted
    Member

    When it's ready/the maintainers have had time to finalize the changelog (including any late merges).

  23. benkehoe commented on Dec 6, 2022

    @benkehoe

    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.

  24. pythoninthegrass commented on Jan 26, 2023

    @pythoninthegrass
    Author

    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-completion

    Appreciate everyone's help 🙏

  25. github-actions commented on Feb 29, 2024

    @github-actions

    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.

  26. locked as resolved and limited conversation to collaborators on Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/cliRelated to the command linekind/bugSomething isn't working as expectedstatus/external-issueIssue is caused by external project (platform, dep, etc)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions