I ran into the same issue while trying to use argcomplete for the first time, but I found a way to make it work.
I assume that like me, you followed the README and used the script activate-global-python-argcomplete
. This script will enable autocompletion on any script that contains PYTHON_ARGCOMPLETE_OK
in the fist 1024 characters of the file. However, when you run it with poetry (or from an packaged executable), the script being scanned will not be yours but poetry's executable file (or a small file wrapper in the executable case).
Solution 1
However, you can make it work by registering your command specifically using register-python-argcomplete
like this:
register-python-argcomplete my-awesome-command > ~/.bash_completion.d/my-awesome-command
(replace my-awesome-command
with the name of your own awesome command)
And then add this to your .bashrc
source ~/.bash_completion.d/my-awesome-command
This worked for me.
Solution 2
I also found a kind of hack that worked to make the executable packaged by poetry compatible with argcomplete's global completion activation:
For this, I renamed my main
method to main_PYTHON_ARGCOMPLETE_OK
, and I updated my pyproject.toml.
[tool.poetry.scripts]
# BEFORE
# my-awesome-command = 'my.awesome.lib:main'
# AFTER
my-awesome-command = 'my.awesome.lib:main_PYTHON_ARGCOMPLETE_OK'
This made sure that the wrapper script generated by poetry contained the string PYTHON_ARGCOMPLETE_OK
, which did the trick ;-)