Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

poetry.bash-completion has multiple syntax errors #4572

Closed
3 tasks done
pythoninthegrass opened this issue Sep 29, 2021 · 25 comments · Fixed by python-poetry/cleo#247
Closed
3 tasks done

poetry.bash-completion has multiple syntax errors #4572

pythoninthegrass opened this issue Sep 29, 2021 · 25 comments · Fixed by python-poetry/cleo#247
Labels
area/cli Related to the command line kind/bug Something isn't working as expected status/external-issue Issue is caused by external project (platform, dep, etc)

Comments

@pythoninthegrass
Copy link

pythoninthegrass commented Sep 29, 2021

  • 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

@pythoninthegrass pythoninthegrass added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Sep 29, 2021
@pythoninthegrass
Copy link
Author

Attached the generated completion file with commented out lines.

@sgaist
Copy link

sgaist commented 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
Copy link
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

@pythoninthegrass
Copy link
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)'

@sgaist
Copy link

sgaist commented 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:

  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.

@pythoninthegrass
Copy link
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)'

@sgaist
Copy link

sgaist commented Oct 6, 2021

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

@pythoninthegrass
Copy link
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.

@ablacklama
Copy link

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

@abn abn added area/cli Related to the command line and removed status/triage This issue needs to be triaged labels Oct 30, 2021
@abn
Copy link
Member

abn commented Oct 30, 2021

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.

@abn
Copy link
Member

abn commented May 11, 2022

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

@LordFckHelmchen
Copy link

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

@koutoftimer
Copy link

@LordFckHelmchen AFAIK, it should affect future release. You probably have to compare release dates and when pull request with fix was accepted (or git log for that release). I've been ranging first too (because it looked like maintainers have closed an open issue), until I've read full discussion. And, as always, patches are welcome.

Thanks to maintainers for the support.

@raffraffraff
Copy link

raffraffraff commented 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
Copy link
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.

@neersighted neersighted reopened this Oct 28, 2022
@raffraffraff
Copy link

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
Copy link

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

@raffraffraff
Copy link

@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
Copy link
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 😄

@Secrus
Copy link
Member

Secrus commented Nov 22, 2022

Completion bugs are now fixed with the incoming release.

@ab
Copy link

ab commented Dec 6, 2022

When is version 1.3.0 expected to be published?

@neersighted
Copy link
Member

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

@benkehoe
Copy link

benkehoe commented 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
Copy link
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 🙏

Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/cli Related to the command line kind/bug Something isn't working as expected status/external-issue Issue is caused by external project (platform, dep, etc)
Projects
None yet
Development

Successfully merging a pull request may close this issue.