poetry
poetry copied to clipboard
Fish completions raise errors but still works
- [x] I am on the latest Poetry version.
- [x] I have searched the issues of this repo and believe that this is not a duplicate.
- [x] If an exception occurs when executing a command, I executed it again in debug mode (
-vvv
option).
- macOS 10.15.7:
- 1.2.0b2:
- fish 3.5:
Issue
I installed the completions as explained in the doc, and completions are working. But there is an error when triggering autocomplete with TAB key :
~/.config/fish/completions/poetry.fish (line 57):
complete -c poetry -f -n '__fish_poetry_e3d63c4129b80bf7_complete_no_subcommand' -a source show -d 'Show information about sources configured for the project.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
I put the last error only, but the console print this error for almost every line of this file.
Screencast if needed
https://user-images.githubusercontent.com/68596777/176383266-927a6d92-c8e9-4674-af02-4cda3fb64486.mp4
The -a
flag takes a single string argument. The completions emitted by poetry need to quote the argument to -a
.
For example, -a "source show"
.
This is known and I am working on fixing completions in cleo
right now.
Please feel free to open a Cleo bug and link back here.
Summary
The problem still exists, but it only occurs when Poetry autocompletion is activated for the first time.
Environments
Steps to reproduce
How should I fix this problem? Shall I upgrade poetry
to a preview version? Or just simply edit
and fix ~/.config/fish/completions/poetry.fish
as follows on our own?
Click to expand
# commands
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'about' -d 'Shows information about Poetry.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'add' -d 'Adds a new dependency to pyproject.toml.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'build' -d 'Builds a package, as a tarball and a wheel by default.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'cache clear' -d "Clears Poetry's cache."
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'cache list' -d "List Poetry's caches."
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'check' -d 'Checks the validity of the pyproject.toml file.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'config' -d 'Manages configuration settings.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'debug info' -d 'Shows debug information.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'debug resolve' -d 'Debugs dependency resolution.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'env info' -d 'Displays information about the current environment.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'env list' -d 'Lists all virtualenvs associated with the current project.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'env remove' -d 'Remove virtual environments associated with the project.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'env use' -d 'Activates or creates a new virtualenv for the current project.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'export' -d 'Exports the lock file to alternative formats.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'help' -d 'Displays help for a command.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'init' -d 'Creates a basic pyproject.toml file in the current directory.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'install' -d 'Installs the project dependencies.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'list' -d 'Lists commands.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'lock' -d 'Locks the project dependencies.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'new' -d 'Creates a new Python project at <path>.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'publish' -d 'Publishes a package to a remote repository.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'remove' -d 'Removes a package from the project dependencies.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'run' -d 'Runs a command in the appropriate environment.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'search' -d 'Searches for packages on remote repositories.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'self add' -d "Add additional packages to Poetry's runtime environment."
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'self install' -d 'Install locked packages (incl. addons) required by this Poetry installation.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'self lock' -d "Lock the Poetry installation's system requirements."
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'self remove' -d "Remove additional packages from Poetry's runtime environment."
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'self show' -d "Show packages from Poetry's runtime environment."
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'self show plugins' -d 'Shows information about the currently installed plugins.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'self update' -d 'Updates Poetry to the latest version.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'shell' -d 'Spawns a shell within the virtual environment.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'show' -d 'Shows information about packages.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'source add' -d 'Add source configuration for project.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'source remove' -d 'Remove source configured for the project.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'source show' -d 'Show information about sources configured for the project.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'update' -d 'Update the dependencies as according to the pyproject.toml file.'
complete -c poetry -f -n '__fish_poetry_b892c35f425489c6_complete_no_subcommand' -a 'version' -d 'Shows the version of the project or bumps it when a valid bump rule is provided.'
The Cleo release has not made it into Poetry yet -- @Secrus is working on getting a release out this week. Due to neglect/bit rot, Cleo is in a pretty rough state release-wise and is difficult to release. The hope is to reset the board here (and there has been a lot of work to that end) so Cleo can release early and often with Poetry's needs.
Now I get it. I'll try to edit ~/.config/fish/completions/poetry.fish
as a walkaround.
After the patch is released in Cleo and applied to Poetry, I should remove my own poetry.fish
and re-generate one for an "official fix"?
Now I get it. I'll try to edit
~/.config/fish/completions/poetry.fish
as a walkaround.After the patch is released in Cleo and applied to Poetry, I should remove my own
poetry.fish
and re-generate one for an "official fix"?
If everything goes according to our plan, update for Cleo should be a part of next minor release of Poetry (1.3 at the moment of writing this). The info will be in the release notes for sure and it will state the need for re-generation of completion files
Damn, closed by mistake as well.
Completion bugs are now fixed with the incoming release.
I still get an error using autocomplete in fish.
Poetry (version 1.3.0) fish, version 3.5.1
log
poetry addcomplete: too many arguments
~/.config/fish/completions/poetry.fish (line 83):
complete -c poetry -A -n '__fish_seen_subcommand_from 'cache clear'' -l all -d 'Clear all entries in the cache.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 97):
complete -c poetry -A -n '__fish_seen_subcommand_from 'debug resolve'' -l extras -d 'Extras to activate for the dependency.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 98):
complete -c poetry -A -n '__fish_seen_subcommand_from 'debug resolve'' -l install -d 'Show what would be installed for the current system.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 99):
complete -c poetry -A -n '__fish_seen_subcommand_from 'debug resolve'' -l python -d 'Python version(s) to use for resolution.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 100):
complete -c poetry -A -n '__fish_seen_subcommand_from 'debug resolve'' -l tree -d 'Display the dependency tree.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 103):
complete -c poetry -A -n '__fish_seen_subcommand_from 'env info'' -l path -d 'Only display the environment\'s path.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 106):
complete -c poetry -A -n '__fish_seen_subcommand_from 'env list'' -l full-path -d 'Output the full paths of the virtualenvs.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 109):
complete -c poetry -A -n '__fish_seen_subcommand_from 'env remove'' -l all -d 'Remove all managed virtual environments associated with the project.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 180):
complete -c poetry -A -n '__fish_seen_subcommand_from 'self add'' -l allow-prereleases -d 'Accept prereleases.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 181):
complete -c poetry -A -n '__fish_seen_subcommand_from 'self add'' -l dry-run -d 'Output the operations but do not execute anything (implicitly enables --verbose).'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 182):
complete -c poetry -A -n '__fish_seen_subcommand_from 'self add'' -l editable -d 'Add vcs/path dependencies as editable.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 183):
complete -c poetry -A -n '__fish_seen_subcommand_from 'self add'' -l extras -d 'Extras to activate for the dependency.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 184):
complete -c poetry -A -n '__fish_seen_subcommand_from 'self add'' -l source -d 'Name of the source to use to install the package.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 187):
complete -c poetry -A -n '__fish_seen_subcommand_from 'self install'' -l dry-run -d 'Output the operations but do not execute anything (implicitly enables --verbose).'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 188):
complete -c poetry -A -n '__fish_seen_subcommand_from 'self install'' -l sync -d 'Synchronize the environment with the locked packages and the specified groups.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 191):
complete -c poetry -A -n '__fish_seen_subcommand_from 'self lock'' -l check -d 'Check that the poetry.lock file corresponds to the current version of pyproject.toml.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 192):
complete -c poetry -A -n '__fish_seen_subcommand_from 'self lock'' -l no-update -d 'Do not update locked versions, only refresh lock file.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 195):
complete -c poetry -A -n '__fish_seen_subcommand_from 'self remove'' -l dry-run -d 'Output the operations but do not execute anything (implicitly enables --verbose).'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 198):
complete -c poetry -A -n '__fish_seen_subcommand_from 'self show'' -l addons -d 'List only add-on packages installed.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 199):
complete -c poetry -A -n '__fish_seen_subcommand_from 'self show'' -l latest -d 'Show the latest version.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 200):
complete -c poetry -A -n '__fish_seen_subcommand_from 'self show'' -l outdated -d 'Show the latest version but only for packages that are outdated.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 201):
complete -c poetry -A -n '__fish_seen_subcommand_from 'self show'' -l tree -d 'List the dependencies as a tree.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 206):
complete -c poetry -A -n '__fish_seen_subcommand_from 'self update'' -l dry-run -d 'Output the operations but do not execute anything (implicitly enables --verbose).'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 207):
complete -c poetry -A -n '__fish_seen_subcommand_from 'self update'' -l preview -d 'Allow the installation of pre-release versions.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 223):
complete -c poetry -A -n '__fish_seen_subcommand_from 'source add'' -l default -d 'Set this source as the default (disable PyPI). A default source will also be the fallback source if you add other sources.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 224):
complete -c poetry -A -n '__fish_seen_subcommand_from 'source add'' -l secondary -d 'Set this source as secondary.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
I still get an error using autocomplete in fish.
Poetry (version 1.3.0) fish, version 3.5.1
log
+1, same issue (and same log) with Poetry 1.3.1 and Fish 3.5.1
The last fix introduced a new issue but now it's too much quoting.
As a workaround search the the output for instances like '__fish_seen_subcommand_from 'self add''
and remove the extra quotes '__fish_seen_subcommand_from self add
Seems to work for me
The last fix introduced a new issue but now it's too much quoting.
@neersighted @Secrus I think this issue should be re-open and fix again.
@garbelini Nice friend! Thank you for you solution. It also works for me.
I'm currently using NeoVim as my editor. I used the following command to quickly replace all these extra-quoted commands. It may also valid in Vim.
:1,$s/__fish_seen_subcommand_from '\(.*\)''/__fish_seen_subcommand_from \1'
Poetry (version 1.3.1) fish, version 3.5.1
/usr/local/share/fish/vendor_completions.d/poetry.fish (line 223):
complete -c poetry -A -n '__fish_seen_subcommand_from 'source add'' -l default -d 'Set this source as the default (disable PyPI). A default source will also be the fallback source if you add other sources.'
^
from sourcing file /usr/local/share/fish/vendor_completions.d/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
/usr/local/share/fish/vendor_completions.d/poetry.fish (line 224):
complete -c poetry -A -n '__fish_seen_subcommand_from 'source add'' -l secondary -d 'Set this source as secondary.'
^
from sourcing file /usr/local/share/fish/vendor_completions.d/poetry.fish
(just pasting last few lines)
Thanks @garbelini for the workaround, and @Dragon1573 for making it easy to fix!
I still see this issue with poetry 1.3.1 and fish 3.6.0 on macosx using homebrew. I'll see if I can submit a follow-up PR (if there isn't already one) in the next day or so.
I see this issue on poetry 1.3.2 on Archlinux
~/.config/fish/completions/poetry.fish (line 223):
complete -c poetry -A -n '__fish_seen_subcommand_from 'source add'' -l default -d 'Set this source as the default (disable PyPI). A default source will also be the fallback source if you add other sources.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 224):
complete -c poetry -A -n '__fish_seen_subcommand_from 'source add'' -l secondary -d 'Set this source as secondary.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
version
$
$ poetry -V
Poetry (version 1.3.2)
$ fish -V
fish: invalid option -- 'V'
$ (1) fish -v
fish, version 3.6.0
I suggest to re-open the issue, as this issue still persists:
(100 more above)
~/.config/fish/completions/poetry.fish (line 223):
complete -c poetry -A -n '__fish_seen_subcommand_from 'source add'' -l default -d 'Set this source as the default (disable PyPI). A default source will also be the fallback source if you add other sources.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
(Type 'help complete' for related documentation)
complete: too many arguments
~/.config/fish/completions/poetry.fish (line 224):
complete -c poetry -A -n '__fish_seen_subcommand_from 'source add'' -l secondary -d 'Set this source as secondary.'
^
from sourcing file ~/.config/fish/completions/poetry.fish
$ poetry --version
Poetry (version 1.3.2)
$ fish --version
fish, version 3.6.0
$ uname -a
Linux TG02 5.15.0-58-generic #64-Ubuntu SMP Thu Jan 5 11:43:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Yep. Poetry 1.3.2 and Fish 3.6.0 here and seeing the same issue.
I edited ~/.config/fish/completions/poetry.fish
and sorted out mismatched single and double quotes. Now this issue is gone.
- Fish 3.6.0
- Python 3.11
- Poetry 1.3.2
The issue is now reopened. Please refrain from "me too" type of comments.
since I haven't actually done the fix, I can share some specific things I've looked at.
completions_command.py#L231-L233 seems like it should be sanitizing a string correctly for substitution on line 258.
The regex provided by @Dragon1573 makes it seem like line 258 is the clear culprit of output strings being generated incorrectly.
The test file also seems like it should be correct: completion/fixtures/fish.txt#L40
so, I'm not actually sure what change to make.
Edit: removed source since it's not relevant (see comments below)
my best guess is that the \\'
is not actually being interpreted correctly and it should have an extra backslash or something, but I haven't set anything up to test any changes I make, so I haven't been able to progress
OHHHHH. I see. the problem is just that the fix wasn't in the release.
This commit (Dec 12, 2022) fixes the issue (because of a typo in the original PR, I assume): https://github.com/python-poetry/cleo/commit/6cc808dd97c811146d72d1c674cfbbdcaf103ce7
but the most recent release of cleo (2.0.1) seems to be Nov 22, 2022? https://github.com/python-poetry/cleo/releases
let me know if the list of releases aren't actually what's included in the released version of poetry, but based on poetry.lock
in the master branch, I'm guessing it is:
https://github.com/python-poetry/poetry/blob/master/poetry.lock#L271-L281
I'm on NixOS, so the default location of the poetry.fish
completion script isn't writable. Setting a .config
file makes it use that, though. The workaround for me was copying the file there and applying the quoting to the -a
args:
cp /run/current-system/sw/share/fish/vendor_completions.d/poetry.fish ~/.config/fish/completions/poetry.fish
sd " -(\w) ([\w\- ]+) -d" ' -$1 "$2" -d' ~/.config/fish/completions/poetry.fish
# Problem should be gone in new shells
At Fish 3.6.0 at complete there is no option -A
from 2.5b1
complete no longer recognises --authoritative and --unauthoritative options, and they are marked as obsolete.
It is still a problem with Poetry 1.4.0 and fish 3.6.0. The problem seems to be that the quoting for the complex commands like "self update" is mangled. I could fix the problem by removing all these quotes around "self update", "self add", ...
It is still a problem with Poetry 1.4.0 and fish 3.6.0.
I believe poetry 1.4.0 still uses cleo 2.0.1, see my above comment.
the 1.4 branch still has cleo 2.0.1 in its poetry.lock file
I'll try to request that cleo get a new release, I'm not sure what the process is for it so I just asked in the discord for now. Will update this comment as appropriate.
Thanks, @drin. I installed a fixed version of the fish completion file in my user config and wait for the update to come.
btw when I asked last week, the response was that cleo maintainers have some bugs they want to fix before they release. I do not know what the bugs are, so I guess there's not much to do.